Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alchemy-custom-model

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alchemy-custom-model

  • 3.2
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

Alchemy::Custom::Model [WIP]

Short description and motivation.

Usage

How to use my plugin.

Installation

Add this line to your application's Gemfile:

gem 'alchemy-custom-model'

And then execute:

$ bundle

Or install it yourself as:

$ gem install alchemy-custom-model

Then run the installer

bin/rails  alchemy_custom_model:install

Usage

  • Generate your model

    • remember to append a column for language:
              t.integer :language_id
      
    • if this model would have a custom url and the relative layout, go to the friendly_id page to make the correct install
    • we can define on the model this attributes to be used for page SEO:
      • text :meta_description
      • text :meta_keywords
      • string :meta_title
      • boolean :robot_follow
      • boolean :robot_index
  • include the model decorator


     include Alchemy::Custom::Model::ModelDecoration

  • attach yours belongs_to relations to alchemy_elements

    # For attachments, the foreign_key is the key defined in the model, can be omitted if it's standard Rails naming
    belongs_to :file, class_name: "Alchemy::Attachment", optional: true, foreign_key: :file_id
    global_id_setter :file

    # For Pictures
    belongs_to :picture, class_name: 'Alchemy::Picture', optional: true, touch: true
    global_id_setter :picture
  • Generate your controller:
    bin/rails g controller Admin::Posts
  • inherit from Alchemy::Custom::Model::Admin::BaseController
  • Create the routes (prepend it to alchemy routes and alchemy_custom_model routes)
  • Build the ability for your recipe:
  class PostAbility
    include CanCan::Ability

    def initialize(user)
      if user.present? && (user.is_admin? or user.has_role?("editor"))
        can :manage, Post #model
        can :manage, :admin_posts #routes to the posts withouth _path
      end
    end

  end
  • build the abilities in ad initializer Es: "menu_and_abilities.rb"
    Alchemy::Modules.register_module({
                                         name: 'Posts', # custom name
                                         order: 2,
                                         navigation: {
                                             name: 'modules.posts',
                                             controller: '/admin/posts', #controller path
                                             action: 'index', #action
                                             icon: "question" # custom icon
                                         }
                                     })
    Alchemy.register_ability(PostAbility)
  • Costruisci la form per il modello

<%= base_form_container do %>
  <div class="form_in_page">
    <%= simple_form_for [:admin,@obj] do |f| %>
      <fieldset>

        <%= f.input :name %>
        <%= rich_text_editor(f, :description) %>
        <%= single_image_input(f, :picture) %>
        <%= single_attachment_input(f, :file) %>
...

  • Per elementi come subobject seguire l'esempio di codice nei test che rivedono le varie opzioni
  • Per modelli che si legano direttamente con componenti di alchemy è necessario utilizzare delle relazioni generiche che identificato il record:
  belongs_to :picture, class_name: 'Alchemy::Picture', touch: true
  belongs_to :alchemy_file_instance, class_name: 'Alchemy::Picture', foreign_key: :picture_id #relazione generica per i files utilizzata nel volume di elfinder
  • Per la visualizzazione creare quindi un layout in Alchemy con attributi custom_model e custom_model_action che serve per identificare la generazione dei link index e show
- name: layout_name_list
  elements: [element_for_list]
  custom_model: "CustomModelClass"
  custom_model_action: "index"
  cache: false

- name: layout_name_show
  elements: [element_for_show]
  custom_model: "CustomModelClass"
  custom_model_action: "show"
  cache: false
  • E' necessario quindi creare le due pagine nella struttura di alchemy

Development

git clone --recursive git@github.com:ArchimediaZerogroup/alchemy-custom-model.git

docker build -t alchemy_custom_image .

docker run -it -p3000:3000 --rm -v "$(pwd)":/app alchemy_custom_image bin/rails s -b 0.0.0.0

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 13 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc