-
Notifications
You must be signed in to change notification settings - Fork 5.5k
How To: Use Recaptcha with Devise
innonate edited this page Dec 28, 2010
·
63 revisions
WARNING: The first draft of this page was done by a total n00b. There wasn't any help here for Recaptcha before, so he hopes this does help some people, but other more experienced should clean this up at a later date.
- Get your keys from Google/Recaptcha
- Install the Recaptcha gem found here (note: for Rails 3 do
gem 'recaptcha', :require => 'recaptcha/rails') - Add
<%= recaptcha_tags %>on your New Registration view (you must have generated Devise views) the line before your submit button. - Create/Update your RegistrationsController to include the following:
class RegistrationsController < Devise::RegistrationsController
def create
if verify_recaptcha
super
session[:omniauth] = nil unless @user.new_record? #This line of code supports OmniAuth
else
build_resource
clean_up_passwords(resource)
flash[:error] = "There was an error with the recaptcha code below. Please re-enter the code and click submit."
render_with_scope :new
end
end
.
.
.
.
end