0

我跟着设计wiki here,当我尝试创建一个新用户时,出现模板错误。这就是我所做的。用devise rails设置recaptcha 3.1

成立到config/environment.rb我的公钥和私钥

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

我加入了宝石我的Gemfile和捆绑安装运行

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

我然后添加一个注册控制器运行rails g控制器注册创建并将其添加到文件中。

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 

我还增加了验证码标签的意见/设计/注册/新

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

然后我编辑的路线文件看起来像:

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

当我检查出我的浏览器中的链接我得到

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/[email protected]/gems/devise-1.4.5/app/views" 

我能够通过删除我添加的控制器位来获得验证码,但当我向文本字段中添加任何文本或将其保留为空时,验证码会通过。

我能弄清楚如何解决这个问题,并会在堆栈溢出时允许我发布解决方案。

回答