Reputation: 1815
I have contact form and sendcontact action respon with js, before use reCaptcha
gem, send contact is works.
Recaptcha.configure do |config| config.public_key = '6LcPi-zzzzzzzzz' config.private_key = '6LcPi-xxxxxxxxx' config.proxy = 'http://localhost:3000/' end
Here's form and 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
when submit form, always display notice Recaptcha unreachable
Upvotes: 2
Views: 976
Reputation: 1815
Solved
Just remove config.proxy = 'http://localhost:3000/'
because I'm not using proxy and http://localhost:3000/
is not proxy so verify captcha not send to server google and show up an alert "recaptcha unreachable"
"Recaptcha Unreachable" show when timeout is over.
Here's rescue Timeout::Error https://github.com/ambethia/recaptcha/blob/master/lib/recaptcha/verify.rb#L53
Upvotes: 3