Rails 创建表单多次提交
Rails create form submitting multiple times
我有一个 rails 表单调用我的控制器中的创建函数,我注意到如果我在页面加载时多次按下提交按钮,我可以多次提交表单.有没有办法防止这种情况发生?我的按钮是:
<%= button_to edit_production_path(id: current_user.default_working_production_id), class: "btn btn-default navbar-btn", :method => :get do %><span class="glyphicon glyphicon-film"></span> Production Settings<% end %>
我的控制器是:
def create
@production = Production.new(production_params)
@production.user = current_user
@production.user_name = current_user.name
if @production.save
redirect_to productions_path
else
render 'new'
end
end`
我注意到您正在使用 edit_path
,这应该是 update
操作的一个 put,但您指定了 :get
作为方法。您确定这将用于您的 create
操作吗?
为了防止重复提交,您需要使用 javascript 禁用,将其添加到按钮。
data: { disable_with: "Submitting..."}
我有一个 rails 表单调用我的控制器中的创建函数,我注意到如果我在页面加载时多次按下提交按钮,我可以多次提交表单.有没有办法防止这种情况发生?我的按钮是:
<%= button_to edit_production_path(id: current_user.default_working_production_id), class: "btn btn-default navbar-btn", :method => :get do %><span class="glyphicon glyphicon-film"></span> Production Settings<% end %>
我的控制器是:
def create
@production = Production.new(production_params)
@production.user = current_user
@production.user_name = current_user.name
if @production.save
redirect_to productions_path
else
render 'new'
end
end`
我注意到您正在使用 edit_path
,这应该是 update
操作的一个 put,但您指定了 :get
作为方法。您确定这将用于您的 create
操作吗?
为了防止重复提交,您需要使用 javascript 禁用,将其添加到按钮。
data: { disable_with: "Submitting..."}