2

So I am trying to use recaptcha gem on localhost. I am getting this error (It's in polish): error_msg

This means something like:

Information for site owner - ERROR: Invalid site key

developement section in secrets.yml:

development:
  secret_key_base: ENV["SECRET_KEY_BASE"]
  recaptcha_public_key: ENV["RECAPTCHA_PUBLIC_KEY"]
  recaptcha_secret_key: ENV["RECAPTCHA_SECRET_KEY"]

recaptcha initializer (recaptcha.rb):

Recaptcha.configure do |config|
  config.public_key  = Rails.application.secrets.recaptcha_public_key
  config.private_key = Rails.application.secrets.recaptcha_secret_key
  config.api_version = 'v2'
end

gemfile:

source 'https://rubygems.org'

ruby '2.2.4'

group :development, :test do
  gem 'dotenv-rails'
  gem 'pry'
end

group :development do
  gem 'dotenv-rails'
  gem 'pry-rails'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'spring'
end

gem "recaptcha", require: "recaptcha/rails"
gem 'will_paginate', '~> 3.0.6'
gem 'rails', '4.2.5.1'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'decent_exposure'
gem 'slim'
gem 'nprogress-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'ffaker'
gem "font-awesome-rails"
gem 'bootstrap-sass', '~> 3.3.6'
gem 'devise'

I didn't implement any logic inside controller yet.

Google says that every key should work on localhost.

I did follow the guide on github. Also I did read this question. Those didn't help me though.

I think I forgot about something obvious. Any ideas?

Community
  • 1
  • 1
dominikduda
  • 325
  • 3
  • 16

1 Answers1

0

Turned out that ENV variables didn't work in recaptcha.rb file. Typing keys straightly there solved the problem.

Although this don't satisfy me and I will try to make ENV vars work there.

Edit: Changing secrets.yml from this:

development:
  secret_key_base: ENV["SECRET_KEY_BASE"]
  recaptcha_public_key: ENV["RECAPTCHA_PUBLIC_KEY"]
  recaptcha_secret_key: ENV["RECAPTCHA_SECRET_KEY"]

to this:

development:
  secret_key_base: ENV["SECRET_KEY_BASE"]
  recaptcha_public_key: <%= ENV["RECAPTCHA_PUBLIC_KEY"] %>
  recaptcha_secret_key: <%= ENV["RECAPTCHA_SECRET_KEY"] %>

solved the problem.

dominikduda
  • 325
  • 3
  • 16