简体   繁体   English

Ruby on Rails和Recaptcha

[英]Ruby on Rails and recaptcha

I have a problem with recaptcha, i follow the next tutorial: 我对Recaptcha遇到问题,请按照下一个教程进行:

https://github.com/ambethia/recaptcha https://github.com/ambethia/recaptcha

And in my app i have the next: 在我的应用程序中,我有下一个:

-In the file config/initializers/recaptcha.rb -在文件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 在文件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 在文件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. 而且我的应用程序运行良好,在我配置Recaptcha之前,在配置Recaptcha之后它不起作用。 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. 我不知道是谁出了问题,我认为还有更多的配置,因为当您填写表格并填写Recaptcha时,您需要传递一个值进行检查,并且此值很好,请保存表格。 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 您能帮我这个吗,我是新手,我会按照课程学习,现在我想安装一个repatcha以获得最小的安全性

You need to setup devise secret key in config/initializers/devise.rb 您需要在config / initializers / devise.rb中设置devise密钥

config.secret_key = 'secret key goes here' 

read devise for more information. 阅读devise以获取更多信息。 or devise tutorial 设计教程

I have this in config/secrets.yml 我在config/secrets.yml有这个

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

With the corrects keys put there. 带有正确的钥匙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM