Recaptcha无法访问的Rails

时间:2013-06-30 10:24:48

标签: ruby-on-rails recaptcha

我有联系表格和send接触动作响应js,在使用reCaptcha gem之前,发送联系人是有效的。

  • gem' recaptcha',:require => '验证码/导轨'
  • 公钥和私钥
  • recaptcha.rb
Recaptcha.configure do |config|
  config.public_key  = '6LcPi-zzzzzzzzz'
  config.private_key = '6LcPi-xxxxxxxxx'
  config.proxy = 'http://localhost:3000/'
end

此处的形式和控制器

  # 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

1 个答案:

答案 0 :(得分:3)

解决

只需删除config.proxy = 'http://localhost:3000/'

即可

因为我没有使用代理,http://localhost:3000/不是代理,所以验证验证码不会发送到服务器谷歌并显示警告&#34; recaptcha unreachable&#34;

&#34; Recaptcha Unreachable&#34;超时结束时显示。

此处拯救超时::错误https://github.com/ambethia/recaptcha/blob/master/lib/recaptcha/verify.rb#L53