2013-02-09 57 views
0

我尝试在设计上使用recaptcha。每当我将代码放入racaptcha并提交表单时,我都会收到“recaptcha-not-reachable”消息。几天前,recaptcha正常工作,但现在我总是收到“recaptcha-not-reachable”的信息,我真的不知道为什么。设计无法找到recaptcha

视图

<div class="password"> 

    <p class="forgot">Forgot your password?</p> 

    <hr class="style-six"> 

    <div class="row"> 
    <div class="email"> 
     <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => {:id => "renew", :class => "form-horizontal", :method => :post }) do |f| %> 

      <div class="control-group mailinput"> 
      <%= f.email_field :email, :placeholder => "Email", :autofocus => true, :required => true %> 
      </div> 

      <%= recaptcha_tags :display => { :theme => 'white' } %> 

      <div class="control-group"> 
      <%= f.button "Re-new password", :class => "btn btn-primary" %> 
      </div> 
     <% end %> 
    </div> 
    </div> 

</div> 

控制器

class PasswordsController < Devise::PasswordsController 
    layout 'xxxx_layout' 

    # POST /resource/password 
    def create 
    if verify_recaptcha 
     self.resource = resource_class.send_reset_password_instructions(resource_params) 
     if successfully_sent?(resource) 
     respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name)) 
     else 
     flash.delete :recaptcha_error 
     flash.now[:error] = t("error.user.noexist") 
     render "passwords/new" 
     end 
    else 
     build_resource 
     clean_up_passwords(resource) 
     flash.now[:alert] = "There was an error with the recaptcha code below. Please re-enter the code." 
     #flash.delete :recaptcha_error 
     render "passwords/new" 
    end 
    end 

end 

get 'password/new' => 'passwords#new', :as => :new_user_password 
post 'password' => 'passwords#create', :as => :user_password 
get 'password/edit' => 'passwords#edit', :as => :edit_user_password 
put 'password' => 'passwords#update' 

/config/initializers/recaptcha.rb

Recaptcha.configure do |config| 
    config.public_key = 'xxxxxxx' 
    config.private_key = 'xxxxxxx' 
    config.proxy = 'http://127.0.0.1:3000' 
end 

的config/application.rb中

require "net/http" 

回答

0

config.proxy = 'http://127.0.0.1:3000'似乎是错误的。这通常是您的开发服务器使用的地址,因此不能有代理。将其更改为您的真实代理或将其注释掉。

现在,reCAPTCHA尝试使用您的rails-app作为代理与recaptcha-servers建立连接。您的rails-app不理解请求(您应该在您的日志中看到一些东西!)并返回一个错误页面。现在,recaptcha试图解析该响应,但不知道如何阅读它,甚至不承认这不是来自recaptcha服务器,而是抱怨无法访问其服务器。