Ruby on Rails和验证码
我有验证码的问题,我按照一个教程:Ruby on Rails和验证码
https://github.com/ambethia/recaptcha
而且在我的应用我有下:
- 在文件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
在文件的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'
.
.
.
在文件app /视图/设计/注册/ 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>
和日志显示下一个:
=> 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_spanly_connected_component'
from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_spanly_connected_component_from'
from /Users/dmuino/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_spanly_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_spanly_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>'
但我检查它首先看起来不错,但它不能正常工作。 而我的应用程序工作正常,在配置recaptcha之前,我配置了它不工作。 我不知道是谁的问题,我认为还有更多的配置,因为填写表单并填写验证码时,您需要传递一个值来检查它,而且这个值很好,保存表单。如果此表单错误,请不要保存表单并显示错误。
你能帮助我,我是新手,我这样做是遵循一个过程,现在我想安装一个验证码安全的minimoun
回答:
您需要安装设计在配置密钥/初始化/ devise.rb
config.secret_key = 'secret key goes here'
的更多信息,请阅读devise。或devise tutorial
回答:
我有这样的config/secrets.yml
shared: recaptcha_site_key: 'site_key here'
recaptcha_secret_key: 'secret_key here'
随着放在那里的校正按键。
以上是 Ruby on Rails和验证码 的全部内容, 来源链接: utcz.com/qa/260594.html