LyricalPanda
LyricalPanda

Reputation: 1414

Condtionally hide Edit action for resource in ActiveAdmin

Is there any way to conditionally hide the 'Edit' link per row on #index of a resource?

For example, say you have a User resource. While a User is active, you can edit the User. However, once the User deactivates their account, it should no longer be editable. The User should still show up on the index page with the View link still.

Thanks!

Upvotes: 2

Views: 2806

Answers (1)

phuk
phuk

Reputation: 1118

You can make your column instead of default_actions column:

index do
  column :actions do |resource|
    links = link_to I18n.t('active_admin.view'), resource_path(resource)
    if resource.is_active?
      links += link_to I18n.t('active_admin.edit'), edit_resource_path(resource)
    end
    links
  end
end

Upvotes: 8

Related Questions