0

I have this recaptcha error We detected that your site is not verifying reCAPTCHA solutions. This is required for the proper use of reCAPTCHA on your site. Please see our developer site for more information.

I did everything exactly but its still there recaptcha checkbox return false even after I checked the button

Here is my codes:

In gemfile

gem "recaptcha", require: "recaptcha/rails"

in config in in initializer in recaptcha.rb

Recaptcha.configure do |config|
  config.site_key   = 'my site key'
  config.secret_key = 'my secret key' 
end

In view:

<%= recaptcha_tags %>

In controller:

def create
  @contact = Contact.new(contact_attributes)
  if verify_recaptcha(model: @contact) && @contact.save
    ContactMailer.message_send(@contact).deliver
    redirect_to contacts_path, notice: "Thank you... Your Message was sent successfully."
  else
    flash.now[:error] = "Please correct the form"
    render :index
  end
end

I even try this in recaptcha.rb

Recaptcha.configure do |config|
  config.public_key = ENV["RECAPTCHA_PUBLIC_KEY"]
  config.private_key = ENV["RECAPTCHA_PRIVATE_KEY"]
end

but I got this error

undefined method `public_key=' for #<Recaptcha::Configuration:0x00007fc132b363e8> (NoMethodError)
Did you mean?  public_send

In this link https://www.google.com/recaptcha/api/siteverify I have { "success": false, "error-codes": [ "missing-input-response", "missing-input-secret" ] }

Not sure what to do please help me and thanks in advance

1 Answer 1

2

Where did you put <%= recaptcha_tags %>?

As per: https://github.com/ambethia/recaptcha/blob/master/lib/recaptcha/configuration.rb

You can:

Recaptcha.configure do |config|
  config.site_key   = 'my site key'
  config.secret_key = 'my secret key' 
end

other wise the gem will automatically pick it from ENV['RECAPTCHA_SECRET_KEY'] and ENV['RECAPTCHA_SITE_KEY'].

This won't work:

Recaptcha.configure do |config|
  config.public_key = ENV["RECAPTCHA_PUBLIC_KEY"]
  config.private_key = ENV["RECAPTCHA_PRIVATE_KEY"]
end

My doubts now goes towards that you place recaptcha_tags in a wrong place (maybe out of the form). that it does not get sent to the controller/backend.

3
  • No it's inside the form
    – nourza
    Commented Sep 2, 2018 at 10:08
  • Do you think I have to add some codes in the controller?
    – nourza
    Commented Sep 2, 2018 at 10:09
  • 1
    Noway this is the solution :D I spent four days trying to figure it out Thank you sooo much :D
    – nourza
    Commented Sep 2, 2018 at 18:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.