railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.89k stars 2.26k forks source link

How to hide custom action from collection view? #2193

Closed kangguru closed 9 years ago

kangguru commented 9 years ago

I'm trying to hide a custom action from models collection/index view. I've already tried plenty variation of

        register_instance_option :member? do
          true
        end

or

        register_instance_option :collection? do
          false
        end

with ? at the end, without (as the internet is not really specific about it)

Then i found out about member actions


member :verify_person

This won't have an effect, besides making the action to loose its icon and falling back to ?

Do i have to use the visibility-option? How to access the current action then? It looks like it just gives me the controller

What am i doing wrong? Help is really appreciated!

rikkipitt commented 9 years ago

It's visible?

E.g.

register_instance_option :visible? do
  current_model = ::RailsAdmin::Config.model(bindings[:abstract_model])
  authorized? && current_model.drafts && bindings[:object].draft?
end

Another example here.

Docs that might help are on the rails_admin wiki here.

rakvium commented 4 years ago

@kangguru, @rikkipitt, so, to remove the custom action button from the list views, it's okay to do something like this, right?:

register_instance_option :visible? do
  # do not show the button on list
  authorized? && bindings[:controller].request.params[:action] != 'index'
end