gpt4 book ai didi

ruby-on-rails - ActiveAdmin 按条件隐藏删除操作

转载 作者:行者123 更新时间:2023-12-01 10:45:18 25 4
gpt4 key购买 nike

我有一些问题。

在 ActiveAdmin 中,我需要按条件隐藏 DELETE 操作。

我是为 #index 做的页。但我不知道如何用 #show 页面来实现这个技巧。

这是代码:

index do
selectable_column
column :id do |package|
link_to package.id, admin_subscription_package_path(package)
end
column :title
column :plan_status
column :duration do |package|
if package.duration == 1
"#{package.duration} day"
else
"#{package.duration} days"
end
end
column 'Price (USD)', :price do |package|
number_to_currency(package.price, locale: :en)
end
column :actions do |object|
raw(
%(
#{link_to 'View', admin_subscription_package_path(object)}
#{(link_to 'Delete', admin_subscription_package_path(object),
method: :delete) unless object.active_subscription? }
#{link_to 'Edit', edit_admin_subscription_package_path(object)}
)
)

end
end

或者也许我可以一次对所有页面更有用。

最佳答案

为此目的使用 action_item:

ActiveAdmin.register MyModel

actions :index, :show, :new, :create, :edit, :update, :destroy

action_item only: :show do
if condition
link_to "Delete whatever", {action: :destroy}, method: :delete, confirm: 'Something will be deleted forever. Sure?'
end
end

end

关于ruby-on-rails - ActiveAdmin 按条件隐藏删除操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27170626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com