I have a form in my Rails app, but it submits multiple times when clicked multiple times. I want to ensure the form submits only once while checking all validations. I tried disabling the button on click, but it only disables the button without sending the data or checking validations.
Please help me. Thanks in advance.
Rails has a built in disable_with
method which you can use on links and buttons. So you can do something like this: button_tag "Checkout", data: { disable_with: "Please wait..." }
. Once your button is clicked once, the button will be disabled ( and no more data sent to your controller ) and the text on the button will be replaced with "Please wait ...".