Delete action for model in rails_admin

I have a problem. In my application, I am using rails_admin gem. All is well, except for one. For some models, I want to make possible only their removal. Is there an easy way to do this?

+5
source share
3 answers

In your rails_admin.rb file, you can add default actions for your models to which you can add exceptions, as shown here .

Here is an example:

config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new do
      except ['SomeModel']
    end
    export
    bulk_delete
    show
    edit do
      except ['SomeOtherModel']
    end
    delete
    show_in_app
end

Here is a link to the rails_admin documentation on actions: https://github.com/sferik/rails_admin/wiki/Actions

+16
source

: config/initilizers/rails_admin.rb, , !

0

You can do this using CanCan: https://github.com/sferik/rails_admin/wiki/Cancan

add this to your file .rb ability :

cannot :manage, Model # disable all actions for this model
can :destroy, Model # enable only to remove
0
source

All Articles