开发者

Setting up recaptcha with devise rails 3.1

开发者 https://www.devze.com 2023-04-05 19:21 出处:网络
I followed the devise wiki here and I get a template error when I try to create a new user. This is what I have done.

I followed the devise wiki here and I get a template error when I try to create a new user. This is what I have done.

Set up my public and private keys in config/environment.rb

ENV['RECAPTCHA_PUBLIC_KEY']='examplepubkey'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'exampleprivkey'

I then added the gem to my gemfile and ran bundle install

gem 'recaptcha', :require => 'recaptcha/rails'

I then added a registrations controller by running rails g controller Registrations create and adding this to the file.

class RegistrationsController < Devise::RegistrationsController

  def create
    if verify_recaptcha
      super
    else
      build_resource
      clean_up_passwords(resource)
      flash[:alert] = "There wa开发者_StackOverflow中文版s an error with the recaptcha code below. Please re-enter the code and click submit."
      render_with_scope :new
    end
  end  

end

I also added the recaptcha tags to views/devise/registrations/new

<div><%= recaptcha_tags %></div>

Then I edited the routes file to look like:

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

When I check out the link in my browser I get

Template is missing

Missing template registrations/new with {:handlers=>[:erb, :builder, :coffee], 
:formats=>[:html], :locale=>[:en, :en]}. Searched in: * 
"/Users/thomascioppettini/rails_projects/want_freight/app/views" *
"/Users/thomascioppettini/.rvm/gems/ruby-1.9.2-p180@standard/gems/devise-1.4.5/app/views"

[edit]

I was able to get the captcha to appear by deleting the bit I added about controllers, but the captcha passes when I add any text into the text field or leave it blank.

[edit2] I was able to figure out how to solve the problem and will post the solution when stack overflow will allow me to.


I was able to get the recaptcha to work by destroying the controller I had set up using rails g controller Registrations create and adding the files by hand as this site suggests. setting up recaptcha with devise

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号