ответ

2
  1. obtain a reCAPTCHA API key
  2. Install gem ReCaptcha
  3. Добавить <%= recaptcha_tags %> на ваш взгляд (views/devise/registrations/new)
  4. Создать файл (в config/initializers) recaptcha.rb и добавьте этот код:

    Recaptcha.configure do |config| 
        config.public_key = 'Your public key' 
        config.private_key = 'Your private key' 
    end 
    
  5. Создать в контроллер: registrations_controller.rb и добавьте этот код

    class RegistrationsController < Devise::RegistrationsController 
        def create 
        if verify_recaptcha 
         super 
        else 
         build_resource(sign_up_params) 
         clean_up_passwords(resource) 
         flash.now[:alert] = "There was an error with the recaptcha code below. Please re-enter the code." 
         flash.delete :recaptcha_error 
         render :new 
        end 
        end 
    end 
    
  6. Обновить ваш Разрабатывают маршрут:

    devise_for :users, controllers: { registrations: 'registrations' } 
    
Смежные вопросы