问题
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
回答1:
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
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
回答2:
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
回答3:
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
回答4:
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 he can replace the link title and the path for the action
来源:https://stackoverflow.com/questions/25727623/activeadmin-actions