2011-05-17 120 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