1
首先,我知道這個問題之前已經被問及幾次回答 - 我已經嘗試瞭解決方案,並沒有運氣。「Devise.secret_key未設置。」部署到Openshift
我正在運行Ruby 2.0.0 Rails 4.2.6,Devise〜> 3.5,並部署到Redhat Openshift。每當我試圖部署(或類似調用Rails的,如用bundle exec rails c
而SSH方式登錄在)我收到以下錯誤:
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+將使用Rails.secret_key_base
作爲它的祕密關鍵,我很確定我已經設置好了。我剛纔的secret_key
以下發生在我的回購:
production.rb
Rails.application.configure do
# Secret key base
config.secret_key_base = ENV["SECRET_KEY_BASE"]
end
我已經驗證環境鍵被設置在Openshift,在Rails的情況下:
[ 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上工作。我發現兩個平臺之間需要的支持文件有很大不同。 – Chowlett
就像我之前提到的那樣,Heroku的確是自動設置了一切。很高興你找到你的答案,雖然:) –