我可以在 ActiveAdmin 中自定义删除警告吗 [英] Can I customize the delete warning in ActiveAdmin

查看:55
本文介绍了我可以在 ActiveAdmin 中自定义删除警告吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rails 应用程序中,销毁操作伴随着警告是很常见的——你确定要删除它吗?"典型的代码如下所示:

It's common in Rails apps to have the Destroy action come along with a warning - "Are you sure you want to delete this?" The typical code looks like this:

link_to("Destroy", "http://www.example.com", :method => :delete, :confirm => "Are you sure?")

ActiveAdmin 中是否有一种方法可以仅为一个模型(不是全局)自定义确认字符串?我看到字符串是从 active_admin.delete_confirmation 翻译键加载的.字符串可以是特定于模型的吗?

Is there a way in ActiveAdmin to customize the confirmation string for one model only (not globally)? I see that the string is loaded from the active_admin.delete_confirmation translation key. Can the string be model-specific?

推荐答案

我不认为您可以通过配置更改字符串.但是,您可以更改默认操作:

I don't think you can change the string with configuration. However you can change the default actions:

索引表:https://github.com/activeadmin/active_admin/blob/master/docs/3-index-pages/index-as-table.md

index do
  column :title
  actions defaults: false do |post|
    link_to("Destroy", "http://www.example.com", :method => :delete, :confirm => "Are you sure?")
  end
end

显示页面:https://github.com/activeadmin/active_admin/blob/master/docs/8-custom-actions.md#action-items

action_item only: :show do
  link_to("Destroy", "http://www.example.com", :method => :delete, :confirm => "Are you sure?")
end

这篇关于我可以在 ActiveAdmin 中自定义删除警告吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆