rajat_474
rajat_474

Reputation: 348

How to resolve RecaptchaError from Rails 3?

I am trying to add reCAPTCHA in my site but i got the following error when i tried to open the registration page.

Error:

Recaptcha::RecaptchaError in Users#new

Showing C:/Site/recaptcha/app/views/users/new.html.erb where line #27 raised:

No public key specified.

Please check my following codes and help me to resolve this error.

config/initializers/recaptcha.rb

Recaptcha.configure do |config|
  config.public_key  = '6LfPjAQTAAAAAHIcZm6r***************'
  config.private_key = '6LfPjAQTAAAAALfyn4pu***************'
end

views/users/new.html.erb

<h3>New User Sign Up</h3>
<% if [email protected]? %>
  <ul>
    <% @user.errors.full_messages.each do |message| %>
      <li><%= message %></li>
    <% end %>
  </ul>
<% end %>
<%= form_for User.new do |f| %>
<div>
  <%= f.label :name %>
  <%= f.text_field :name %>
</div>
<div>
  <%= f.label :email %>
  <%= f.text_field :email %>
</div>
<div>
  <%= f.label :password %>
  <%= f.password_field :password %>
</div>
<div>
  <%= f.label :password_confirmation %>
  <%= f.password_field :password_confirmation %>
</div>
<div>
  <%= recaptcha_tags %>
</div>
<div>
  <%= f.submit "Sign Up" %>
</div>
<% end %>

Actually the error is showing at this line "<%= recaptcha_tags %>".Please help me to resolve this error.

Upvotes: 3

Views: 986

Answers (2)

Shadoath
Shadoath

Reputation: 1071

Just updated my rails app with version 4.0.0 of this recaptcha gem and found that the environmental variable names changed.

From:

ENV['RECAPTCHA_PUBLIC_KEY']  = '6LfPjAQTAAAAAHIcZm6r***************'
ENV['RECAPTCHA_PRIVATE_KEY'] = '6LfPjAQTAAAAALfyn4pu***************'

To:

ENV['RECAPTCHA_SITE_KEY']   = '6LfPjAQTAAAAAHIcZm6r***************'
ENV['RECAPTCHA_SECRET_KEY'] = '6LfPjAQTAAAAALfyn4pu***************'

Upon updating my application.yml file Recaptcha was back to working like a charm.

Upvotes: 2

Raj
Raj

Reputation: 980

Use this on your environment.rb file:

ENV['RECAPTCHA_PUBLIC_KEY']  = '6LfPjAQTAAAAAHIcZm6r***************'
ENV['RECAPTCHA_PRIVATE_KEY'] = '6LfPjAQTAAAAALfyn4pu***************'

then restart server.

Upvotes: 0

Related Questions