0

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

看法

<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

配置/应用程序.rb

require "net/http"
4

1 回答 1

0

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

就像现在一样,reCAPTCHA 尝试使用您的 rails-app 作为代理来建立与 recaptcha-servers 的连接。您的 rails-app 不理解请求(您可能应该在日志中看到某些内容!)并返回错误页面。现在 recaptcha 尝试解析该响应,但不知道如何读取它,甚至识别出这不是来自 recaptcha 服务器并抱怨无​​法访问其服务器。

于 2013-02-12T07:49:12.660 回答