gpt4 book ai didi

ruby-on-rails - 在 Active Admin Rails 中自定义按钮和成功消息

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

我想自定义以下内容

  1. 操作名称,例如“添加用户”=>“创建用户”、“编辑用户”=>“更新用户”等
  2. 删除、创建和编辑时显示成功消息,例如“用户已成功创建”=>“客户已成功创建”
  3. 在编辑和删除旁边的显示页面上添加创建按钮

最佳答案

是的,这是可能的。

Actions Name like "Add User" => "Create User", "Edit User" => "Update User" etc

您可以拥有f.actions,而不是

<%= f.actions do %>
<%= f.action :submit, as: :button, label: 'Create User' %>
<%= f.action :cancel, as: :link %> # change it to button if needed
<% end %>

ActiveAdmin 使用 formattastic,read more here .

Success Message On Delete, Create and Edit like "user successfully created" => "customer successfully created"

def create # or any other action
super do |format| # this is important - override the original implementation
redirect_to(
admin_users_path,
notice: 'Your custom message for successful user creation'
) and return
end
end

你也可以尝试这个:

def create # or any other action
super do |format| # this is important - override the original implementation
flash[:notice] = 'Your custom message for successful user creation'
# you do understand, that if you have different routes you should change this, right?
redirect_to admin_users_path
end
end

Add A Create Button On Show Page beside edit and delete

  action_item only: :show  do
link_to 'Create new user', new_admin_users_path
end

关于ruby-on-rails - 在 Active Admin Rails 中自定义按钮和成功消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33945285/

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