How to hide Add new option in Rails Admin

吃可爱长大的小学妹 提交于 2019-12-03 02:40:00

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

config.actions do
  new do
    except ['Some Model']
  end
end

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

To have multiple models you must put each model in single quotes:

For example consider the following configuration:

config.actions do
  dashboard
  index do
    except ['Address']
  end
  new do
    except ['Address'', 'Employee'', 'Setting',]
  end
  export
  show
  edit do
    except ['Employee']
  end
end

This means that:

  • Addresses are not included on the navbar on the left
  • You cannot add a new address employee or setting with the "add new" button
  • There is no pencil icon in the index view for Employees for editing.
  • If you had a User model you could see it in the navbar, edit it, and add a new one on the index page.
  • You can export every model, but not bulk delete them.

Implemented it with Cancan. You can refer to above answer to do it in rails admin way.

URL : https://github.com/sferik/rails_admin/wiki/CanCan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!