在活动管理员中自定义按钮和成功消息 Rails
Customize Button And Success Message In Active Admin Rails
我想自定义以下内容
- 动作名称如 "Add User" => "Create User"、"Edit User" => "Update User" 等
- 删除、创建和编辑成功消息 "user successfully created" => "customer successfully created"
- 在编辑和删除旁边的显示页面上添加创建按钮
是的,有可能。
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 使用 formtastic,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
我正在为第二个添加答案(参考上面),但是上面的验证错误不起作用所以我自定义它可以更好地帮助你
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
我想自定义以下内容
- 动作名称如 "Add User" => "Create User"、"Edit User" => "Update User" 等
- 删除、创建和编辑成功消息 "user successfully created" => "customer successfully created"
- 在编辑和删除旁边的显示页面上添加创建按钮
是的,有可能。
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 使用 formtastic,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
我正在为第二个添加答案(参考上面),但是上面的验证错误不起作用所以我自定义它可以更好地帮助你
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