在 rails gem active admin 我想从 default_actions 中删除删除选项,而我仍然需要编辑和显示操作,有什么办法吗?
问问题
20345 次
5 回答
108
您添加actions
对每个 Active Admin 资源的调用:
ActiveAdmin.register Foobar do
actions :all, :except => [:destroy]
end
于 2011-10-12T12:56:55.127 回答
10
在某些时候我遇到了这个问题,因为销毁方法,“删除”按钮没有消失
actions :all, except: [:destroy]
controller do
def destroy # => Because of this the 'Delete' button was still there
@user = User.find_by_slug(params[:id])
super
end
end
于 2014-07-07T08:11:52.647 回答
2
接受的答案引发了一个异常,“参数数量错误”所以我这样做是为了排除删除按钮(:destroy action)
ActiveAdmin.register YourModel do
actions :index, :show, :new, :create, :update, :edit
index do
selectable_column
id_column
column :title
column :email
column :name
actions
end
于 2017-04-29T08:19:49.727 回答
2
Another way to remove actions from default_actions for an ActiveAdmin
resource is via config
variable, like:
ActiveAdmin.register MyUser do
config.remove_action_item(:destroy)
...
end
One way is already mentioned in the accepted answer via
actions
method.
于 2019-03-12T00:20:13.963 回答
0
如果要完全删除删除销毁按钮,请使用:
actions :all, except: [:destroy]
但是如果删除按钮需要基于资源属性的条件(例如关联数据或状态)。
在索引页面:
index do
# ...
actions defaults: false do |row|
if can? :read, row
text_node link_to "View", admin_resource_path(row), class: "view_link"
end
if can? :edit, row
text_node link_to "Edit", admin_resource_path(row), class: "edit_link"
end
if can? :destroy, row
text_node link_to I18n.t('active_admin.delete'), admin_resource_path(row), method: :delete, data: { confirm: I18n.t('active_admin.delete_confirmation') }, class: "delete_link" if row.deletable?
end
end
end
现在是复杂的部分,我不得不敲了几次头才能在显示页面上控制它:
config.remove_action_item(:destroy) # will remove the destroy button
action_item only: :show do
link_to I18n.t('active_admin.delete'), admin_resource_path(resource), method: :delete, data: { confirm: I18n.t('active_admin.delete_confirmation') }, class: "delete_link" if resource.deletable?
end
对不起我糟糕的格式。
于 2017-10-09T15:49:55.397 回答