Recaptcha appears only after page refresh - Rails 4 - develops

I installed recaptcha according to the gem instructions, however, when I look at the sign_up page (using Devise), catcha does not appear until I refresh the page.

Looking through other comments, it is recommended to disable turbolinks (which I use) by changing the sign_in link to:

<%= link_to "Sign up", new_registration_path, "data-no-turbolink" => true %><br />

I tried this, but I still do not get captcha until I refresh the page.

Relevant Code:

Views / invent / register / new.html.erb

................
<%= recaptcha_tags %>
................

/controllers/users/registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController
  def create
    if !verify_recaptcha
     flash.delete :recaptcha_error
     build_resource
     resource.valid?
     resource.errors.add(:base, "There was an error with the recaptcha code below. Please re-enter the code.")
     clean_up_passwords(resource)
     respond_with_navigational(resource) { render_with_scope :new }
   else
    flash.delete :recaptcha_error
    super
   end
  end

  def clean_up_passwords(*args)
   # Delete or comment out this method to prevent the password fields from 
   # repopulating after a failed registration
  end
 end
+4
source share
2 answers

, - ":" :

<%= link_to "Sign up", new_user_registration_path, "data-no-turbolink" => true, class: "btn btn-primary btn-med" %>
+3

def create  
  if resource.valid? && !verify_recaptcha  
    clean_up_passwords(resource)  
    flash.delete :recaptcha_error   

  elsif !resource.valid? && verify_recaptcha  
    clean_up_passwords resource  
    respond_with resource  

  elsif !resource.valid? && !verify_recaptcha  
    flash.now[:alert] = "Recaptcha error"  
    flash.delete :recaptcha_error  
    clean_up_passwords resource  
    respond_with resource  

  end  
 end  

/devize/registration/new.html.erb

<%= recaptcha_tags  display: {theme:  'red', tabindex:  5}, ssl: false, noscript: false %>
0

All Articles