skip to Main Content

I have a problem with recaptcha, i follow the next tutorial:

https://github.com/ambethia/recaptcha

And in my app i have the next:

-In the file config/initializers/recaptcha.rb

Recaptcha.configure do |config|
  config.site_key  = Rails.application.secrets.recaptcha_site_key
  config.secret_key = Rails.application.secrets.recaptcha_secret_key
  config.proxy = ‘http://www.google.com/recaptcha/api/verify’
end
  • In the file gemfile

    .
    .
    .

    gem 'bootstrap-sass', '~> 3.3.7'
    gem 'jquery-rails', '~> 4.3'
    gem 'devise', '~> 4.2'
    
    gem 'toastr-rails', '~> 1.0'
    
    gem 'recaptcha', require: 'recaptcha/rails'
    gem 'bcrypt'
    .
    .
    .
    

In the file app/views/devise/registrations/new.html.erb

<div class="row">
  <div class="col-md-4 col-md-offset-4">

    <h2 class="text-center">Sign up</h2>
    <br/>

    <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
      <%= render 'shared/devisemes' %>

      <div class="form-group">
        <%= f.text_field :fullname, autofocus: true, placeholder: "Full Name", class: "form-control" %>
      </div>

      <div class="form-group">
        <%= f.email_field :email, autofocus: true, placeholder: "Email", class: "form-control" %>
      </div>

      <div class="form-group">
        <%= f.password_field :password, autocomplete: "off", placeholder: "Password", class: "form-control" %>
      </div>
      <br/></br>

      <div class="actions">
        <%= f.submit "Sign up", class: "btn btn-normal btn-block" %>
      </div>
    <% end %>

    <hr/>
    <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path, class: "btn btn-facebook btn-block" %>
  </div>
    <div class="form-group">
  <%= raw receptcha_tags %>


  </div>
</div>

And the log show the next:

=> Booting Puma
=> Rails 5.1.4 application starting in development 
=> Run `rails server -h` for more startup options
Exiting
/Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/devise-4.3.0/lib/devise/rails/routes.rb:498:in `raise_no_secret_key': Devise.secret_key was not set. Please add the following to your Devise initializer: (RuntimeError)

  config.secret_key = '00a17c1ccd9a5dea9b6c845e0e5e46fc29d4e42e82e1146dd5df3b219b05bd7b5304125eb800b7187aa200aa096d3287d8b720f1a034439015ad1f11ffef2d1b'

Please ensure you restarted your application after installing Devise or setting the key.
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/devise-4.3.0/lib/devise/rails/routes.rb:226:in `devise_for'
    from /Users/dmuino/Desktop/StJames/config/routes.rb:5:in `block in <top (required)>'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in `instance_exec'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in `eval_block'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:408:in `draw'
    from /Users/dmuino/Desktop/StJames/config/routes.rb:1:in `<top (required)>'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `block in load'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in `load'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `block in load_paths'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `each'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `load_paths'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:18:in `reload!'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:41:in `block in updater'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/file_update_checker.rb:81:in `execute'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:42:in `updater'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:31:in `execute_if_updated'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application/finisher.rb:128:in `block in <module:Finisher>'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `run'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:59:in `block in run_initializers'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:58:in `run_initializers'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:353:in `initialize!'
    from /Users/dmuino/Desktop/StJames/config/environment.rb:5:in `<top (required)>'
    from config.ru:3:in `require_relative'
    from config.ru:3:in `block in <main>'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:55:in `initialize'
    from config.ru:in `new'
    from config.ru:in `<main>'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:49:in `eval'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:49:in `new_from_string'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/builder.rb:40:in `parse_file'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/server.rb:319:in `build_app_and_options_from_config'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/server.rb:219:in `app'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:24:in `app'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/server.rb:354:in `wrapped_app'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:80:in `log_to_stdout'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:42:in `start'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in `block in perform'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
    from /Users/dmuino/Desktop/StJames/bin/rails:9:in `require'
    from /Users/dmuino/Desktop/StJames/bin/rails:9:in `<top (required)>'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /Users/dmuino/Desktop/StJames/bin/spring:15:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

But i check it and firstly it seems good, but it don’t work fine.
And my app was working fine, before i configure the recaptcha, after configure recaptcha it don’t work.
I don’t know who is the problem, and i think there was more configuration, because when you fill the form and fill the recaptcha, you need to pass a value to check it, and this value is fine, save the form. And if this form was wrong don’t save the form and show a error.

Could you help me with this, I am newbie and i do this follow a course, and now i want install a recaptcha for a minimoun of security

2

Answers


  1. Chosen as BEST ANSWER

    I have this in config/secrets.yml

     shared:
      recaptcha_site_key: 'site_key here'
      recaptcha_secret_key: 'secret_key here'
    

    With the corrects keys put there.


  2. You need to setup devise secret key in config/initializers/devise.rb

    config.secret_key = 'secret key goes here' 
    

    read devise for more information. or devise tutorial

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search