ActiveAdmin actions

做~自己de王妃 提交于 2019-12-22 01:34:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!