I know this is a little late but I just had to solve this problem so hopefully my response can help someone else. Basically, since my form is a create action, I edited my create.js file to update the token on failed submission. Here's how:
Here's a portion of my form where I render a partial that include my captcha tag:
<div class="form-group captcha captcha-lead_creation_modal">
<%= render "potential_clients/captcha_field", action: 'lead_creation_modal' %>
<div class="col-lg-12 d-flex m-t-20">
<%= f.submit 'Request More Information', class: "btn btn-md btn-block btn-info-gradiant" %>
Here's the complete partial: potential_clients/captcha_field:
<%= recaptcha_execute(action) %>
Finally, in my create.js I do the following:
// other error handling / success code goes here
$(".captcha-lead_creation_modal").html("<%= j render 'potential_clients/captcha_field', action: 'lead_creation_modal' %>")
This will re-render the portion of the form with the token and since it hits the helper function, a new token is generated!
Nice! Thank you so much for sharing your solution!
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.