muichkine
muichkine

Reputation: 2940

ActiveAdmin actions

is there a way to specify in ActiveAdmin's index page of a model what actions are allowed, things like:

index do
  actions :edit
end

index do
  actions only: :edit
end

do not work. What's the correct syntax?

Appreciated.

bundle show activeadmin
/home/muichkine/.rvm/gems/ruby-2.1.2/bundler/gems/active_admin-9cfc45330e5a

Upvotes: 28

Views: 30046

Answers (5)

Andrey Deineko
Andrey Deineko

Reputation: 52357

Add whatever actions you want to be available by using actions (it is usually put under model definition):

ActiveAdmin.register YourModel do
  actions :index, :show, :create, :edit, :update
  # ...
end

If you want to specify the method for certain action, you can do

action_item only: :show  do
  link_to 'Edit', action: :edit # so link will only be available on show action
end

Upvotes: 38

KNejad
KNejad

Reputation: 2508

If you want multiple custom actions, instead of dealing with joining the links manually like Ziv Barber did, you can also use the item method like so:

actions defaults: true do |user|
  item "Report", report_admin_user_path(user), method: :put
  item "Unlock", unlock_admin_user_path(user), method: :put
end

Upvotes: 2

muichkine
muichkine

Reputation: 2940

According to source code, https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/index_as_table.rb#L80

if one want to change the actions in the index he should go with

actions defaults: false do |sample|
  link_to t('active_admin.edit'), admin_sample_path(sample)
end

where you can replace the link title and the path for the action

For Example:

    actions defaults: false do |user|
      link_to t('active_admin.view'), admin_user_path(user)
    end

Note:

Keep in mind that add the path correctly like for show it should be admin_user_path(:id) and for index it should be admin_users_path :)

Upvotes: 6

Ziv Barber
Ziv Barber

Reputation: 741

Example how to play with the action column. In this example I just re-implemented the default one, but you can do powerful coding here:

column :actions do |item|
  links = []
  links << link_to('Show', item_path(item))
  links << link_to('Edit', edit_item_path(item))
  links << link_to('Delete', item_path(item), method: :delete, confirm: 'Are you sure?')
  links.join(' ').html_safe
end

Upvotes: 17

maximus ツ
maximus ツ

Reputation: 8065

Do this way,

ActiveAdmin.register Foobar do
  actions :all, :except => [:destroy]
end

or

ActiveAdmin.register Foobar do
  actions :only => :edit
end

Need to be specified at resource level not in method definition

Upvotes: 7

Related Questions