我有联系表单和 sendcontact 操作响应与 js,在使用 reCaptcha
gem 之前,发送联系方式是有效的。
- gem 'recaptcha', :require => 'recaptcha/rails'
- 公钥和私钥
- recaptcha.rb
Recaptcha.configure do |config| config.public_key = '6LcPi-zzzzzzzzz' config.private_key = '6LcPi-xxxxxxxxx' config.proxy = 'http://localhost:3000/' end
这是表单和 Controller
# contact form
<%= form_for Contact.new, :url => { :action => "sendcontact" }, :remote => true do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :message %><br />
<%= f.text_area :message, :style => 'height:200px;width:300px;resize:vertical;' %>
</div>
<div class="field">
<%= recaptcha_tags %>
</div>
<div class="actions">
<%= f.submit "Send", :class => 'btn btn-success btn-large' %>
</div>
<% end %>
#controller
def sendcontact
@contact = Contact.new(params[:contact])
if verify_recaptcha
@contact.save!
respond_to do |format|
flash.now[:notice] = 'Thank you for contacting me'
format.js
end
else
respond_to do |format|
format.js
end
end
end
提交表单时,始终显示通知Recaptcha unreachable
最佳答案
已解决
只需删除config.proxy = 'http://localhost:3000/'
因为我没有使用代理,并且 http://localhost:3000/
不是代理,因此验证验证码不会发送到 google 服务器并显示警报“recaptcha 无法访问”
超时结束时显示“Recaptcha Unreachable”。
这里是救援超时::错误 https://github.com/ambethia/recaptcha/blob/master/lib/recaptcha/verify.rb#L53
关于ruby-on-rails - 验证码无法访问 Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17389374/