I have tried setting this up based on previously asked questionshere on stack overflow but haven’t been able to get it working. The captcha is showing up on my forms but a user can still register without filling in the recaptcha.
I’m working with the following instructions.
https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise
- I’ve got my private and public recaptcha keys
Environment.rb
ENV['RECAPTCHA_PUBLIC_KEY'] = 'mykey1234567'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'mykey1234567'
- I’ve installed the recaptcha gem.
Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'devise', '1.1.7'
gem "jquery-rails"
gem 'recaptcha', :require => 'recaptcha/rails'
- I’ve added recaptcha tags to my registration view.
new.html.erb
<%= recaptcha_tags %>
<p><%= f.submit "Sign up" %></p>
-
Created Registrations Controller
rails generate controller Registrations create
Registrations Controller
class 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
I am supposed to edit my routes file but not sure what exactly which may be the cause of the issue.
My Routes File
devise_for :troopers, :path => "troopers", :path_names => { :sign_in => "login", :sign_out => "logout", :sign_up => "register" }
Thanks for any help.
You also need to tell Devise to use your customized RegistrationsController. You do this by specifying the
:controllersoptions in yourdevise_fordeclaration. Without this theDevise::RegistrationsControlleris called, which probably explains why recaptcha isn’t working.