Recaptcha rails 5 错误
Recaptcha rails 5 error
我在生产中 secrets.yml 中 recaptcha 识别我的密钥时遇到错误。在开发中,一切正常!
我能够使用 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:
我正在尝试遵循本教程 https://github.com/ambethia/recaptcha,但它没有提供有关将密钥投入生产的详细信息。
我尝试了很多方法,比如在键前面添加export
,将它们放在不同的文件中,并检查secrets.yml 是否有任何语法错误。我还确保我使用的是 RECAPTHCA_SITE_KEY
而不是 RECAPTCHA_PUBLIC_KEY
.
此外,我已将我的域放在 recaptcha 的站点中。
如果您能帮助我解决问题并解释我出现错误的原因,我将不胜感激。
这是我的 secrets.yml 在生产中:
production:
secret_key_base: ...SECRET_KEY...
RECAPTCHA_SITE_KEY: "...SITE_KEY..."
RECAPTCHA_PRIVATE_KEY: "...PRIVATE_KEY..."
谢谢!
您需要配置 recaptcha 以通过添加初始化文件 config/initializers/recaptcha.rb
:
从您的 secrets.yml
中提取密钥
# 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
我在生产中 secrets.yml 中 recaptcha 识别我的密钥时遇到错误。在开发中,一切正常!
我能够使用 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:
我正在尝试遵循本教程 https://github.com/ambethia/recaptcha,但它没有提供有关将密钥投入生产的详细信息。
我尝试了很多方法,比如在键前面添加export
,将它们放在不同的文件中,并检查secrets.yml 是否有任何语法错误。我还确保我使用的是 RECAPTHCA_SITE_KEY
而不是 RECAPTCHA_PUBLIC_KEY
.
此外,我已将我的域放在 recaptcha 的站点中。
如果您能帮助我解决问题并解释我出现错误的原因,我将不胜感激。
这是我的 secrets.yml 在生产中:
production:
secret_key_base: ...SECRET_KEY...
RECAPTCHA_SITE_KEY: "...SITE_KEY..."
RECAPTCHA_PRIVATE_KEY: "...PRIVATE_KEY..."
谢谢!
您需要配置 recaptcha 以通过添加初始化文件 config/initializers/recaptcha.rb
:
secrets.yml
中提取密钥
# 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