sferik/rails_admin — Issue #1004: Show custom action for specific model only
Author: JohnGoodman
Created: 2012-02-23 19:39:12+00:00
State: open

Hey All,

I wrote a custom action for my rails_admin app. I only want this action to show on in the list view of a specific model. I was finally able to achieve this by adding the action name to the default action list like so:

config.actions do
# root actions
dashboard # mandatory
# collection actions
index # mandatory
new
export
history_index
bulk_delete
# member actions
show
edit
delete
history_show
show_in_app
duplicate_program # This is the custom action
end

In my rails_admin_duplicate_program.rb file, I set the visibility like this:

register_instance_option :visible do
bindings[:object].class.name.downcase == 'program'
end

Gists of these files are here:
https://gist.github.com/1894506
https://gist.github.com/1894513

My question is, is there a better way to only show a custom action for a specified model?

Thanks.