我正在处理活动的admin gem。我只是想隐藏仅显示页面的删除链接。所以,我添加了以下代码
ActiveAdmin.register ArticlesSkill do
menu :parent => "ReadUp"
actions :index, :show, :new, :create, :update, :edit
index do
column :name, sortable: :name
column :description
column "" do |resource|
links = ''.html_safe
links += link_to I18n.t('active_admin.view'), resource_path(resource), :class => "member_link edit_link"
links += link_to I18n.t('active_admin.edit'), edit_resource_path(resource), :class => "member_link edit_link"
if Article.where(articles_skill_id: resource.id).blank?
links += link_to I18n.t('active_admin.delete'), resource_path(resource), :method => :delete, :confirm => I18n.t('active_admin.delete_confirmation'), :class => "member_link delete_link"
else
# links += link_to I18n.t('active_admin.delete'), "#", :confirm => ("This Skill has A related Article. You Can't Delete This Now"), :class => "member_link delete_link"
links += link_to I18n.t('active_admin.delete'), resource_path(resource), :method => :delete, :confirm => I18n.t('active_admin.delete_confirmation'), :class => "member_link delete_link"
end
links
end
end
end
这是从显示页面删除删除链接,但在索引页面中,如果我尝试删除记录,则显示此错误,
The action 'destroy' could not be found for Admin::ArticlesSkillsController
任何人都可以帮助我吗?请。
答案 0 :(得分:4)
所以这是旧的,但我发现自己需要在索引页面和显示页面上有条件地隐藏编辑/销毁按钮,虽然这对我有很大帮助,但我觉得更完整的答案可能会更快地帮助别人。
让我们一起去......
这个是相对简单的,只是不包括“行动”,而是包括你自己的:
index do
id_column
column :name
column :foo
column :bar
column :funded
# don't do this
# actions
# instead make our own column, with no name so it looks like AA
column "" do |resource|
links = ''.html_safe
links += link_to I18n.t('active_admin.view'), resource_path(resource), class: "member_link show_link"
if !resource.funded?
links += link_to I18n.t('active_admin.edit'), edit_resource_path(resource), class: "member_link edit_link"
links += link_to I18n.t('active_admin.delete'), resource_path(resource), method: :delete, confirm: I18n.t('active_admin.delete_confirmation'), class: "member_link delete_link"
end
links
end
end
在这里,我们必须从显示页面中删除所有默认按钮,然后添加我们想要的按钮:
# Remove the buttons from the show page
config.action_items.delete_if { |item| item.display_on?(:show) }
# Then add in our own conditional Edit Button
# (note: 'loan' is the registered model's name)
action_item :edit, only: [ :show ] , if: proc { !loan.funded? } do
link_to "#{I18n.t('active_admin.edit')} Loan", edit_resource_path(resource)
end
# and our Delete Button
action_item :delete, only: [ :show ] , if: proc { !loan.funded? } do
link_to "#{I18n.t('active_admin.delete')} Loan", resource_path(resource), method: :delete, confirm: I18n.t('active_admin.delete_confirmation')
end
# and our (custom) Fund Loan Button
action_item :fund_loan, only: [ :show ], if: proc { !loan.funded? } do
link_to 'Fund Loan', fund_loan_admin_loan_path(loan), method: :patch
end
# our custom actions code
member_action :fund_loan, method: :patch do
if resource.fund
redirect_to resource_path(resource), notice: 'Loan funded'
else
redirect_to resource_path(resource), alert: "Loan funding failed : #{resource.errors.full_messages}"
end
end
希望有助于找到偶然发现此页面的人。快乐编码=]
答案 1 :(得分:2)
传递:也销毁到动作方法调用,或传递:全部
actions :all
答案 2 :(得分:2)
从ActiveAdmin删除操作的简单方法,例如在控制器中删除
Add totals from field_id=198 for logged-in [userid] if
wp_frm_item_metas field_id=253 where meta_value=Complete
and
wp_frm_item_metas field_id=278 wheremeta_value=Yes
and
wp_frm_item_metas field_id=212 is between Begin and End date
wp_frm_item_metas field_id=270wheremeta_value=[userid of logged in user]
答案 3 :(得分:1)
config.action_items.delete_if { |item|
item.display_on?(:show)
}
action_item only: :show do
link_to I18n.t('active_admin.edit'), edit_resource_path(resource) end
此代码用于从显示页面中删除操作删除链接,而不是操作。
答案 4 :(得分:-2)
我已经解决了我的问题。这是一件简单的事情。
只需覆盖你的控制器。
controller do
def destroy
super
end
end