提交后禁用Rails中的link_to按钮以防止重复提交

时间:2022-11-24 10:56:06

In my Rails app I have a modal that pops up when trying to close an object (in this case a call). The modal pops up with a standard Rails link_to like so:

在我的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' %>

In form objects I'm able to disable the submit button but setting the data attribute of disable_with, but Im not sure if this option is available in the link_to helper.

在表单对象中,我可以禁用提交按钮,但设置disable_with的数据属性,但我不确定link_to帮助程序中是否有此选项。

<%= f.button "Update Unit", class: 'btn btn-info', data: {disable_with: "<i class='icon-spinner'></i>Updating..."} %>

My goal is to prevent duplication clicks of the button once the action hits the controller.

我的目标是在操作到达控制器后防止按钮的重复点击。

1 个解决方案

#1


0  

As per the link_to documentation, you can use the option disable_with as data attribute.

根据link_to文档,您可以使用disable_with选项作为数据属性。

: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.

:disable_with - 提交表单时,此参数的值将用作提交按钮的禁用版本的值。此功能由不显眼的JavaScript驱动程序提供。

#1


0  

As per the link_to documentation, you can use the option disable_with as data attribute.

根据link_to文档,您可以使用disable_with选项作为数据属性。

: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.

:disable_with - 提交表单时,此参数的值将用作提交按钮的禁用版本的值。此功能由不显眼的JavaScript驱动程序提供。