我使用rails_admin。
有人知道如何在更新前显示确认消息(带动作)吗?
答案 0 :(得分:0)
我会创建自定义操作或覆盖现有操作。像这样:
class Update2
RailsAdmin::Config::Actions.register(self)
register_instance_option :visible? do
#
end
register_instance_option :link_icon do
# your icon here
end
register_instance_option :http_methods do
[:get, :post]
end
register_instance_option :controller do
Proc.new do
if request.post?
@object.update
flash[:notice] = "Updated #{@object.name}."
redirect_to show_path
end
end
end
end
然后创建页面app / views / rails_admin / main / update2.html.haml
%h3
= "Are you sure you want to update '#{@object.name}'
= link_to 'Update', update2_path, method: 'post', class: "btn btn-danger"
= link_to 'Cancel', show_path, class: "btn btn-primary"
单击Update2后,您将通过GET转到该页面。然后在POST它将实际更新。