2011-05-17 61 views
3

我的設計Recaptcha無法正常工作,因爲我可以跳過它並仍然註冊設計:Recaptcha無法正常工作

我跟着Devise維基在 - https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise,並得到了一切工作接受我遇到了上述問題。

這裏是我的代碼:

應用程序/控制器/用戶/ registrations.rb

class Users::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 

的routes.rb

YourApp::Application.routes.draw do 

    devise_for :users do 
    root :to => "devise/registrations#new" 
    get "/" => "devise/registrations#new" 
    post '/' => 'registrations#new', :as => :new_user_registration 
    match '/', :to => 'devise/registrations#new'  
    . 
    . 
    . 
    . 
    . 
    end 

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

    namespace :user do 
    root :to => "home#index" 
    end 

配置/初始化/驗證碼。 rb

Recaptcha.configure do |config| 
    config.public_key = 'mykey123456789' 
    config.private_key = 'mykey13456789' 
end 

這可能不起作用,因爲我處於測試模式,而不是我的域名?

幫助,將不勝感激!

回答

1

在environment.rb文件把下面的:

ENV['RECAPTCHA_PUBLIC_KEY'] = 'mykey123456789' 
ENV['RECAPTCHA_PRIVATE_KEY'] = 'mykey123456789' 

不可正對你的域名可能取決於你如何註冊鍵是一個問題。

+0

這是註冊的鑰匙?我訪問http://www.google.com/recaptcha並註冊,放入我的網站並將密鑰放入recaptcha.rb中。我把你的代碼放在我的environment.rb裏面,沒有改變。 – LearningRoR 2011-05-18 17:04:55

+1

是的,這就是你如何註冊密鑰。如果你使用過你的網站,那麼我相信你應該只在你的域名上使用這些特定的密鑰?你在本地或你的域名?對不起,environment.rb沒有幫助。我查看了我對recaptcha的使用情況,沒有看到任何其他差異。 – John 2011-05-19 04:55:04

+0

我在我的本地主機上。 – LearningRoR 2011-05-19 17:58:37