我尝试在设计上使用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
配置/ application.rb中
require "net/http"
答案 0 :(得分:0)
config.proxy = 'http://127.0.0.1:3000'
似乎错了。这通常是您的开发服务器使用的地址,因此不能有代理。将其更改为您的真实代理或将其注释掉。
就像现在一样,reCAPTCHA尝试使用rails-app作为代理建立与recaptcha-servers的连接。你的rails-app不理解请求(你应该在日志中看到一些内容!)并返回错误页面。现在,recaptcha尝试解析该响应,但不知道如何阅读它,甚至认识到这不是来自recaptcha服务器并且抱怨无法访问其服务器。