Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Add new option in Rails Admin

I am customizing Rails Admin : https://github.com/sferik/rails_admin , i need to disable/hide "Add new" option for some model.

enter image description here

Any help will save lot time for me. Thanks in advance

like image 375
Senthil Avatar asked Aug 12 '13 15:08

Senthil


2 Answers

I use the following to achieve this on a specific model. Hopefully, this helps:

config.actions do
  new do
    except ['Some Model']
  end
end
like image 151
RubeOnRails Avatar answered Sep 23 '22 16:09

RubeOnRails


The answer is in the configuration documentation for actions. By default, all actions are possible, including new. To customize the possible actions, in config.actions in config/initilizers/rails_admin.rb, list all the actions you want to support, leaving out the ones you don’t want to support. For example, here is a config block that allows all of the default actions except for new:

# config/initilizers/rails_admin.rb
RailsAdmin.config do |config|
  config.actions do
    # root actions
    dashboard
    # collection actions 
    index
    # `new` is NOT allowed
    export
    history_index
    bulk_delete
    # member actions
    show
    edit
    delete
    history_show
    show_in_app
  end
end
like image 44
Rory O'Kane Avatar answered Sep 23 '22 16:09

Rory O'Kane