Short description and motivation.
How to use my plugin.
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
Generate your model
t.integer :language_id
include the model decorator
include Alchemy::Custom::Model::ModelDecoration
* attach yours belongs_to relations to alchemy_elements
```ruby
# 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 %>