I am customizing Rails Admin : https://github.com/sferik/rails_admin , i need to disable/hide "Add new" option for some model.
Any help will save lot time for me. Thanks in advance
I am customizing Rails Admin : https://github.com/sferik/rails_admin , i need to disable/hide "Add new" option for some model.
Any help will save lot time for me. Thanks in advance
I use the following to achieve this on a specific model. Hopefully, this helps:
config.actions do
new do
except ['Some Model']
end
end
except [User]
–
Schwa 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
new
action when doing anything with that model and reenabling it when accessing any other model. –
Gerigerianna can
calls related to the new
action, though I hadn’t realized that that was relevant. –
Gerigerianna 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:
User
model you could see it in the navbar, edit it, and add a new one on the index page.Implemented it with Cancan. You can refer to above answer to do it in rails admin way.
© 2022 - 2024 — McMap. All rights reserved.
http://localhost:3000/dashboard/user/new
:/ – Bore