3

my Devise Recaptcha isn't working correctly because I can skip right over it and still register.

I followed the Devise wiki at - https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise and got everything working accept i encountered the problem above.

Here is my code:

app/controllers/users/registrations.rb

class Users::RegistrationsController < Devise::RegistrationsController
    def create
        if verify_recaptcha
            super
        else
            build_resource
            clean_up_passwords(resource)
            flash[:alert] = "There was an error with the recaptcha code below. Please re-enter the code and click submit."
            render_with_scope :new
        end
    end
end

routes.rb

YourApp::Application.routes.draw do

  devise_for :users do
    root :to => "devise/registrations#new"
    get "/" => "devise/registrations#new"
    post '/' => 'registrations#new', :as => :new_user_registration 
    match '/', :to => 'devise/registrations#new'    
    .
    .
    .
    .
    .
  end

  devise_for :users, :controllers => { :registrations => "users/registrations" }

  namespace :user do
    root :to => "home#index"
  end

config/initializers/recaptcha.rb

Recaptcha.configure do |config|
    config.public_key  = 'mykey123456789'
    config.private_key = 'mykey13456789'
end

It is possible it doesn't work because i am in test mode and not on my domain name?

Help would be appreciated!

LearningRoR
  • 26,582
  • 22
  • 85
  • 150

2 Answers2

1

In environment.rb put the following:

ENV['RECAPTCHA_PUBLIC_KEY']  = 'mykey123456789'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'mykey123456789'

Not being on your domain name may be a problem depending on how you registered the keys.

John
  • 4,362
  • 5
  • 32
  • 50
  • Is this registering the keys? i went to http://www.google.com/recaptcha and signed up, put in my website and put the keys inside the recaptcha.rb. I put your code above inside of my environment.rb and no change. – LearningRoR May 18 '11 at 17:04
  • 1
    Yes, that is how you register the keys. If you used your website, then I believe you should be using those specific keys only on your domain? Are you on localhost or your domain? Sorry, the environment.rb didn't help. I looked over my use of recaptcha and did not see any other differences. – John May 19 '11 at 04:55
  • You should create a new set of keys where you use your localhost as your domain, and then switch to the ones you are currently using when you upload to production. – John May 20 '11 at 06:25
  • I tried to add the localhost by inserting -> http://localhost:3000/ but it says it must be a domain like .com or .net. By default it claims it detects localhost. I also tried new keys but still no luck. – LearningRoR May 20 '11 at 13:30
0

This was an issue with not having ImageMagick or RMagick installed, had to go through the nonsense to get this working.

These were my trials & tribulations:

ImageMagick - "CORE_RL_magick_.dll not found" or how to install RMagick on windows with ruby 1.9.2

Community
  • 1
  • 1
LearningRoR
  • 26,582
  • 22
  • 85
  • 150