未能在heroku的设计设置中找到ENV

这个没有版本控制你的密钥的要点很棒,而且我现在已经使用了几次不再版本化我的rails secret-key-base。

我尝试将它用于heroku上的devise secret_key,我的尝试失败了。 它在dev中工作正常,但拒绝让我推送到heroku – 说我创建的设计密钥(与上面的要点相同)没有设置。

我使用硬编码的密钥(检入git),但不是在我使用以下内容时:

Devise.setup do |config| config.secret_key = ENV['DEVISE_SECRET_KEY'] ... 

(与相关的环境变量三重检查,它在那里)

在推送到heroku期间,似乎在预编译资产时失败了

 $ git push heroku master ... (bundle stuff here) Running: rake assets:precompile rake aborted! Devise.secret_key was not set. Please add the following to your Devise initializer: config.secret_key = '0cfa796871e0... /tmp/build_.../vendor/bundle/ruby/1.9.1/gems/devise-3.1.1/lib/devise/rails/routes.rb:446:in `raise_no_secret_key' /tmp/build_.../vendor/bundle/ruby/1.9.1/gems/devise-3.1.1/lib/devise/rails/routes.rb:195:in `devise_for' /tmp/build_.../config/routes.rb:2:in `block in ' ...( rest of the long stacktrace with little of interest here) 

在routes目录中运行“devise_for”时会引发错误。 相关专线:

 MyApp::Application.routes.draw do devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout'} 

实际设计gem中的相关行是:

  raise_no_secret_key unless Devise.secret_key 

所以它真的只是检查secret_key是否已设置。

只是为了确认…我检查了heroku配置,事实上我确实把一个密钥放在该名称下的环境中。

 DEVISE_SECRET_KEY: 3f844454bee...(more here) RAILS_SECRET_KEY_BASE: 04bf569d4e...(more here) 

因为它是在一个rake任务而不是应用程序 – 我猜这就是为什么它无法进入ENV ???

我可能会开始寻找解决方案的任何想法?

你想在之前(在编译时)使用config var它实际上可用于你的应用程序(在slug编译时)。

尝试打开Heroku Labs:user-env-compile

我怀疑它会解决问题。

如果它在编译时中断,则需要启用user-env-compile, heroku labs:enable user-env-compile以在应用程序引导以编译资产时使环境可用。

Heroku上不再提供user-env-compile实验室function。

我正在使用Ruby 2.2.2p95和Rails 4.2.4。

对我有用的是,在config / initializers / devise.rb中:

 config.secret_key = ENV['DEVISE_SECRET_KEY'] if Rails.env.production? 

然后在heroku中添加DEVISE_SECRET_KEY配置变量,设置为您想要的任何值。 好的做法是生成与开发和测试的默认值相同长度的东西。

希望这可以帮助。