【发布时间】:2016-10-01 19:16:31
【问题描述】:
首先,我知道这个问题已经被问过并回答了好几次 - 我已经尝试了给出的解决方案,但没有运气。
我正在运行 Ruby 2.0.0 Rails 4.2.6、Devise ~> 3.5,并部署到 Redhat Openshift。每当我尝试部署(或类似地调用 Rails,例如在 ssh 中使用 bundle exec rails c)时,我都会收到以下错误:
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = '2d229ab5ed60d38692a890544be96c8108040e18e4653832e2688dc1bed378afe6ef0f3386692f3c9b65336aba5b8e8e500accc2eadc6e70d6bc6c92f41c97fb'
Please ensure you restarted your application after installing Devise or setting the key.
据我了解,Rails 4+ 下的 Devise 将使用 Rails.secret_key_base 作为其密钥,我很确定我已经设置了。我的仓库中出现了以下secret_key:
production.rb
Rails.application.configure do
# Secret key base
config.secret_key_base = ENV["SECRET_KEY_BASE"]
end
我已经在 Rails 上下文中验证了环境键是在 Openshift 上设置的:
[ repo]\> bundle exec env | grep SECRET_KEY
SECRET_KEY_BASE=c509...
我也尝试过更明确地将密钥设置为 Devise:
Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key`
# by default. You can change it below and use your own secret key.
config.secret_key = ENV["SECRET_KEY_BASE"] if Rails.env == 'production'
end
..但我仍然遇到同样的错误。
我错过了什么?
【问题讨论】:
-
您可以尝试在 Heroku 上部署您的项目吗? Heroku 在 rails 5 上自动为我执行此操作。看看问题是否仍然存在。
-
@AkashAggarwal - 我没试过;但我不确定我是否希望它只适用于heroku。我发现两个平台之间的支持文件需要有很大的不同。
-
好吧,就像我之前提到的那样,Heroku 确实确实自动设置了所有内容。很高兴你找到了答案:)
标签: ruby-on-rails ruby-on-rails-4 devise openshift