Activeadmin: Can you disable edit or delete in a show view?

Created on 31 May 2011  路  4Comments  路  Source: activeadmin/activeadmin

I see the default action_items in the resource_controller class, but can't figure out how to disable them via the active_admin model config. Is that possible?

# Default Action Item Links
action_item :only => :show do
  if controller.action_methods.include?('edit')
    link_to("Edit #{active_admin_config.resource_name}", edit_resource_path(resource))
  end
end

action_item :only => :show do
  if controller.action_methods.include?("destroy")
    link_to("Delete #{active_admin_config.resource_name}",
      resource_path(resource), 
      :method => :delete, :confirm => "Are you sure you want to delete this?")
  end
end

action_item :except => [:new, :show] do
  if controller.action_methods.include?('new')
    link_to("New #{active_admin_config.resource_name}", new_resource_path)
  end
end

-Ryan

Most helpful comment

Nevermind. I see how you can open up the controller in the config like this:

ActiveAdmin.register User do
  controller do
    actions :all, :except => [:edit, :destroy]
  end
end

Thanks.

All 4 comments

Nevermind. I see how you can open up the controller in the config like this:

ActiveAdmin.register User do
  controller do
    actions :all, :except => [:edit, :destroy]
  end
end

Thanks.

Do you want to only disable the buttons? Or the entire actions?

To disable the actions use:

actions :index, :show

Or

actions :except => [:edit, :update]

Currently there is no supported mechanism to turn on and off individual action items that you didn't create.

On 2011-05-31, at 7:41 AM, ryanwoodreply@reply.github.com wrote:

I see the default action_items in the resource_controller class, but can't figure out how to disable them via the active_admin model config. Is that possible?

# Default Action Item Links
action_item :only => :show do
if controller.action_methods.include?('edit')
link_to("Edit #{active_admin_config.resource_name}", edit_resource_path(resource))
end
end

action_item :only => :show do
if controller.action_methods.include?("destroy")
link_to("Delete #{active_admin_config.resource_name}",
resource_path(resource),
:method => :delete, :confirm => "Are you sure you want to delete this?")
end
end

action_item :except => [:new, :show] do
if controller.action_methods.include?('new')
link_to("New #{active_admin_config.resource_name}", new_resource_path)
end
end

-Ryan

Reply to this email directly or view it on GitHub:
https://github.com/gregbell/active_admin/issues/134

@ryanwood No need to open the controller class, you can call #actions directly from the registration block

And what if you need only to remove the buttons because you are using a belongs_to association of Inherited Resources?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Awatatah picture Awatatah  路  3Comments

therealx picture therealx  路  3Comments

gcerquant picture gcerquant  路  3Comments

dheerajk3 picture dheerajk3  路  3Comments

zhdwwf picture zhdwwf  路  4Comments