rails 从 Heroku 迁移到专用服务器后,为 #<Recaptcha 生成 dragonfly returns 未定义方法 `public_key='
rails generate dragonfly returns undefined method `public_key=' for #<Recaptcha after migrating from Heroku to dedicated server
站点已从 Heroku 迁移到专用 Ubuntu 服务器,迁移后站点正常运行,除了托管在 S3 上的图像。
加载带有图片的页面时,会出现以下类型的错误return:
Completed 200 OK in 1428.8ms (Views: 505.5ms | ActiveRecord: 322.2ms)
Started GET "/system/images/W1siZiIsIjIwMTYvMDkvMjIvMTMvMjQvMjUvMjE1L05hb21pX1NhbnNvbS5qcGciXSxbInAiLCJ0aHVtYiIsIjM2MHgzNjAjIl1d/picture.jpg" for ip at 2016-11-23 00:27:24 +0000
Dragonfly::Configurable::NotConfigured (You need to configure Dragonfly::DataStorage::S3DataStore with bucket_name):
我可以看到应用程序没有在 gemfile 中列出 dragonfly,因为 Heroku 似乎做事有点不同,并重新安装了 dragonfly,但是在尝试生成配置文件时出现以下错误 return编辑
# rails generate dragonfly
appdir/config/initializers/recaptcha.rb:2:in `block in <top (required)>': undefined method `public_key=' for #<Recaptcha::Configuration:0x0000000521f070> (NoMethodError)
from appdir/vendor/bundle/ruby/2.0.0/gems/recaptcha-4.0.0/lib/recaptcha.rb:30:in `configure'
from appdir/config/initializers/recaptcha.rb:1:in `<top (required)>'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `load'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `block in load'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:236:in `load_dependency'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `load'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/engine.rb:593:in `block (2 levels) in <class:Engine>'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/engine.rb:592:in `each'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/engine.rb:592:in `block in <class:Engine>'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:30:in `instance_exec'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:30:in `run'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:55:in `block in run_initializers'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:54:in `each'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:54:in `run_initializers'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/application.rb:136:in `initialize!'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/railtie/configurable.rb:30:in `method_missing'
from appdir/config/environment.rb:5:in `<top (required)>'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `block in require'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:236:in `load_dependency'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/application.rb:103:in `require_environment!'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Recaptcha 本身似乎工作正常,bundle install 没有 return 任何错误,但我无法让 dragonfly 工作。
recaptcha.rb 看起来像这样
Recaptcha.configure do |config|
config.public_key = 'public key'
config.private_key = 'private key'
config.api_version = 'v2'
end
我创建了不存在的 .env 文件,内容如下:
export RECAPTCHA_PUBLIC_KEY = 'public key'
export RECAPTCHA_PRIVATE_KEY = 'private key'
我也尝试手动添加到 config/environments/production.rb 和 config/environments/development.rb 以下:
recaptcha_public_key= "[PUBLIC KEY]"
recaptcha_private_key= "[PRIVATE KEY]"
我不确定我在这里遗漏了什么,在从 Heroku 迁移到独立系统后,有人对蜻蜓和 recaptcha 有任何经验吗Linux 系统
他们用版本 4 更改了 API,因此如果您通过 gemfile 安装它而不指定版本并且它默认为版本 4,您需要在配置中进行更改。
来自他们的CHANGELOG.md:
4.0.0 - 2016-11-14
public_key -> site_key and private_key -> secret_key
将您的 config/initializers/recaptcha.rb
更改为:
Recaptcha.configure do |config|
config.site_key = 'public key'
config.secret_key = 'private key'
...
站点已从 Heroku 迁移到专用 Ubuntu 服务器,迁移后站点正常运行,除了托管在 S3 上的图像。
加载带有图片的页面时,会出现以下类型的错误return:
Completed 200 OK in 1428.8ms (Views: 505.5ms | ActiveRecord: 322.2ms)
Started GET "/system/images/W1siZiIsIjIwMTYvMDkvMjIvMTMvMjQvMjUvMjE1L05hb21pX1NhbnNvbS5qcGciXSxbInAiLCJ0aHVtYiIsIjM2MHgzNjAjIl1d/picture.jpg" for ip at 2016-11-23 00:27:24 +0000
Dragonfly::Configurable::NotConfigured (You need to configure Dragonfly::DataStorage::S3DataStore with bucket_name):
我可以看到应用程序没有在 gemfile 中列出 dragonfly,因为 Heroku 似乎做事有点不同,并重新安装了 dragonfly,但是在尝试生成配置文件时出现以下错误 return编辑
# rails generate dragonfly
appdir/config/initializers/recaptcha.rb:2:in `block in <top (required)>': undefined method `public_key=' for #<Recaptcha::Configuration:0x0000000521f070> (NoMethodError)
from appdir/vendor/bundle/ruby/2.0.0/gems/recaptcha-4.0.0/lib/recaptcha.rb:30:in `configure'
from appdir/config/initializers/recaptcha.rb:1:in `<top (required)>'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `load'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `block in load'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:236:in `load_dependency'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:245:in `load'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/engine.rb:593:in `block (2 levels) in <class:Engine>'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/engine.rb:592:in `each'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/engine.rb:592:in `block in <class:Engine>'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:30:in `instance_exec'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:30:in `run'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:55:in `block in run_initializers'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:54:in `each'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/initializable.rb:54:in `run_initializers'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/application.rb:136:in `initialize!'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/railtie/configurable.rb:30:in `method_missing'
from appdir/config/environment.rb:5:in `<top (required)>'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `block in require'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:236:in `load_dependency'
from appdir/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.18/lib/active_support/dependencies.rb:251:in `require'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/application.rb:103:in `require_environment!'
from appdir/vendor/bundle/ruby/2.0.0/gems/railties-3.2.18/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Recaptcha 本身似乎工作正常,bundle install 没有 return 任何错误,但我无法让 dragonfly 工作。
recaptcha.rb 看起来像这样
Recaptcha.configure do |config|
config.public_key = 'public key'
config.private_key = 'private key'
config.api_version = 'v2'
end
我创建了不存在的 .env 文件,内容如下:
export RECAPTCHA_PUBLIC_KEY = 'public key'
export RECAPTCHA_PRIVATE_KEY = 'private key'
我也尝试手动添加到 config/environments/production.rb 和 config/environments/development.rb 以下:
recaptcha_public_key= "[PUBLIC KEY]"
recaptcha_private_key= "[PRIVATE KEY]"
我不确定我在这里遗漏了什么,在从 Heroku 迁移到独立系统后,有人对蜻蜓和 recaptcha 有任何经验吗Linux 系统
他们用版本 4 更改了 API,因此如果您通过 gemfile 安装它而不指定版本并且它默认为版本 4,您需要在配置中进行更改。
来自他们的CHANGELOG.md:
4.0.0 - 2016-11-14
public_key -> site_key and private_key -> secret_key
将您的 config/initializers/recaptcha.rb
更改为:
Recaptcha.configure do |config|
config.site_key = 'public key'
config.secret_key = 'private key'
...