提交后禁用 Rails 中的 link_to 按钮以防止重复提交
Disable link_to button in Rails after submit to prevent duplication submission
在我的 Rails 应用程序中,我有一个模式会在尝试关闭对象(在本例中为调用)时弹出。模式弹出标准 Rails link_to 像这样:
<%= link_to "Close Call #{call.incident_number}", close_call_path(call), :method => :post, :class => 'btn btn-danger btn-large btn-block' %>
在表单对象中,我可以禁用提交按钮,但可以设置 disable_with 的数据属性,但我不确定 link_to 助手中是否提供此选项。
<%= f.button "Update Unit", class: 'btn btn-info', data: {disable_with: "<i class='icon-spinner'></i>Updating..."} %>
我的目标是防止在操作触及控制器后重复点击按钮。
根据 link_to
文档,您可以使用选项 disable_with
作为 data
属性。
:disable_with
- Value of this parameter will be used as the value for a disabled version of the submit button when the form is submitted. This feature is provided by the unobtrusive JavaScript driver.
在我的 Rails 应用程序中,我有一个模式会在尝试关闭对象(在本例中为调用)时弹出。模式弹出标准 Rails link_to 像这样:
<%= link_to "Close Call #{call.incident_number}", close_call_path(call), :method => :post, :class => 'btn btn-danger btn-large btn-block' %>
在表单对象中,我可以禁用提交按钮,但可以设置 disable_with 的数据属性,但我不确定 link_to 助手中是否提供此选项。
<%= f.button "Update Unit", class: 'btn btn-info', data: {disable_with: "<i class='icon-spinner'></i>Updating..."} %>
我的目标是防止在操作触及控制器后重复点击按钮。
根据 link_to
文档,您可以使用选项 disable_with
作为 data
属性。
:disable_with
- Value of this parameter will be used as the value for a disabled version of the submit button when the form is submitted. This feature is provided by the unobtrusive JavaScript driver.