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"
我能夠通過刪除我添加的控制器位來獲得驗證碼,但當我向文本字段中添加任何文本或將其保留爲空時,驗證碼會通過。
我能弄清楚如何解決這個問題,並會在堆棧溢出時允許我發佈解決方案。