1

In my rails app i use devise gem, and simple captcha from here https://github.com/pludoni/simple-captcha

and i want to add this captcha only for sign up action, and i do it, but i'm new to rails and didn't know - what i done is good or not? Maybe somebody could take a look? Also this will be good "tutorial" for other people who use this chain...

so from gem doc's i use model-variant, i add what i need to model, add to devise permitted param's captcha and captcha_key params, and in controller i have such code:

 def create
    build_resource(sign_up_params)
    if resource.valid_with_captcha?
      resource_saved = resource.save
    end
    yield resource if block_given?
    if resource_saved
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_flashing_format?
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

do i it good or wrong? if wrong please help to do in right way, also now it work's... just that i didn't is it good or not...

brabertaser19
  • 5,678
  • 16
  • 78
  • 184

1 Answers1

0

Here is full documentation from devise it self.

https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise

Rahul Chaudhari
  • 2,230
  • 21
  • 29