【发布时间】:2016-08-20 00:26:52
【问题描述】:
我使用 rails_admin。
有人知道我如何在更新之前显示确认消息(带有操作)吗?
【问题讨论】:
标签: ruby-on-rails-4 rails-admin
我使用 rails_admin。
有人知道我如何在更新之前显示确认消息(带有操作)吗?
【问题讨论】:
标签: ruby-on-rails-4 rails-admin
我会创建一个自定义操作或覆盖现有的操作。像这样的:
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 上它实际上会更新。
【讨论】: