`disable_with` to prevent double clicks
If a link or button initiates a request that takes a long time to respond then the user (being a user) might click the link or button again. Depending on the code implemented on the server this could put the application into a bad state.
Rails has a handy feature that will disable a link or button after the user has clicked it, disable_with
:
<%= link_to('something',
something_path(something),
data: {
disable_with: "Please wait..."
}
)
%>
In Rails 5.0 and up sumbit buttons have disable_with
set by default. To disable disable_with
use:
data: { disable_with: false }
Tweet