I have contact form and sendcontact action respon with js, before use reCaptcha
gem, send contact is works.
- gem 'recaptcha', :require => 'recaptcha/rails'
- public and private key
- recaptcha.rb
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