我想自定义以下内容
答案 0 :(得分:5)
是的,这是可能的。
操作名称如"添加用户" => "创建用户","编辑用户" => "更新 用户"等
而不是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使用formtastic,read more here。
成功消息关于删除,创建和编辑,例如&#34;用户成功 创建&#34; =&GT; &#34;客户成功创建&#34;
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
在编辑和删除旁边的显示页面上添加创建按钮
action_item only: :show do
link_to 'Create new user', new_admin_users_path
end
答案 1 :(得分:3)
我正在添加第二个答案(从上面引用),但是上面的验证错误不起作用所以我自定义它可以帮助你更好
controller do
def update
super do |format|
if !@your_object.errors.any?
redirect_to(
admin_my_localities_path,
notice: 'custom message.'
) and return
end
end
end
def destroy
super do |format|
if !@your_object.errors.any?
redirect_to(
admin_my_localities_path,
notice: 'custom message.'
) and return
else
redirect_to(
admin_my_localities_path,
alert: 'custom error.'
) and return
end
end
end
end