Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Show custom action for specific model only #1004

Closed
JohnGoodman opened this Issue · 8 comments

6 participants

@JohnGoodman

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.

@stantona

I'm having the same issue. It would be nice to have an easy, less verbose way to specify custom actions on models.
One use case where this would be appropriate is "reset password" on a user.

@neokain

+1

@bbenezech
Collaborator

Proposed API:

actions do
  update_password do
    only User, Admin
    # except Stuff, Stuff2
  end
  ...
end

That should do it.

Meanwhile you guys can also use Cancan

can :update_password, [User, Admin]

@bbenezech bbenezech was assigned
@JohnGoodman

Nice, the proposed API looks good. Thanks.

@neokain

Thank for your help.

@kritik

I can propose to switch on not in config.actions, but

config.model User do
  actions do
    update_password
  end
end
@meetme2meat

undefined method `only' for #RailsAdmin::Config::Actions::MarkAsManager:0xc209728 when using the above API

actions do
  mark_as_manager do
    only User, Admin
    # except Stuff, Stuff2
  end
  ...
end
@kritik

@meetme2meat it was just a proposal

@bbenezech bbenezech closed this in 710715e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.