简体   繁体   English

重新安装导轨5错误

[英]Recaptcha rails 5 error

I am having an error with recaptcha recognizing my keys in secrets.yml in production. 我在重新生产时无法识别出secrets.yml中的密钥时遇到了错误。 In development, everything works fine! 在开发中,一切正常!

I was able to upload successfully my site using capistrano and nginx, I placed the recaptcha keys in secrets.yml but I get the following error in rails logs. 我能够使用capistrano和nginx成功上传我的网站,将recaptcha密钥放置在secrets.yml中,但是在rails日志中出现以下错误。

[70624ace-d7c2-41d4-a312-81e558237559] app/views/contacts/_new.html.erb:1:in `_app_views_contacts__new_html_erb___113748072819217608_34958780'
[70624ace-d7c2-41d4-a312-81e558237559] app/views/welcome/index.html.erb:97:in `_app_views_welcome_index_html_erb__2483501284442413835_31069860'
I, [2018-02-13T15:06:06.655443 #23369]  INFO -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f] Started GET "/" for 66.249.70.22 at 2018-02-13 15:06:06 +0000
I, [2018-02-13T15:06:06.656262 #23369]  INFO -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f] Processing by WelcomeController#index as HTML
I, [2018-02-13T15:06:06.657082 #23369]  INFO -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f]   Rendering welcome/index.html.erb within layouts/application
I, [2018-02-13T15:06:06.666156 #23369]  INFO -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f]   Rendered contacts/_new.html.erb (8.3ms)
I, [2018-02-13T15:06:06.666316 #23369]  INFO -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f]   Rendered welcome/index.html.erb within layouts/application (9.1ms)
I, [2018-02-13T15:06:06.666485 #23369]  INFO -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f] Completed 401 Unauthorized in 10ms
F, [2018-02-13T15:06:06.667938 #23369] FATAL -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f]
F, [2018-02-13T15:06:06.668014 #23369] FATAL -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f] ActionView::Template::Error (No site key specified.):
F, [2018-02-13T15:06:06.668157 #23369] FATAL -- : [1abb6e09-8ebd-41a3-ad0c-ea88749d804f]      9:

I am trying to follow this tutorial https://github.com/ambethia/recaptcha , but it does not provide much detail about placing the keys in production. 我正在尝试遵循本教程https://github.com/ambethia/recaptcha ,但是它没有提供有关将密钥投入生产的详细信息。

I have tried many things, like adding export in front of the keys, placing them in different files, and checking secrets.yml for any syntax error. 我尝试了很多事情,例如在键之前添加export ,将它们放置在不同的文件中,以及检查secrets.yml是否存在语法错误。 I have also made sure that I am using RECAPTHCA_SITE_KEY instead of RECAPTCHA_PUBLIC_KEY . 我还确保我使用的是RECAPTHCA_SITE_KEY而不是RECAPTCHA_PUBLIC_KEY

Also, I have placed my domain in recaptcha's site. 另外,我已经将我的域放置在recaptcha的站点中。

I would appreciate if you could help me solve the problem as well as provide some explanation of why I was having the error. 如果您能帮助我解决问题并提供为什么出现错误的解释,我们将不胜感激。

This is my secrets.yml in production: 这是我在生产中的secrets.yml:

production:
  secret_key_base: ...SECRET_KEY...
  RECAPTCHA_SITE_KEY: "...SITE_KEY..."
  RECAPTCHA_PRIVATE_KEY: "...PRIVATE_KEY..."

Thanks! 谢谢!

You need to configure recaptcha to pull the keys from your secrets.yml by adding an initializer file, config/initializers/recaptcha.rb : 您需要配置的reCAPTCHA拉从您的钥匙secrets.yml通过添加一个初始化文件, 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_PRIVATE_KEY]
  # Uncomment the following line if you are using a proxy server:
  # config.proxy = 'http://myproxy.com.au:8080'
end

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

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