This gist on not version-controlling your secret keys is awesome, and I've used it a few times now for no-longer versioning my rails secret-key-base.
I tried using it for the devise secret_key on heroku and my attempt failed miserably. It works fine in dev, but refused to allow me to push to heroku - saying the devise key which I created (in the same way as in the gist above) wasn't set.
I got it working with a hard-coded secret-key (checked into git), but not when I used the following:
Devise.setup do |config|
config.secret_key = ENV['DEVISE_SECRET_KEY']
...
(with associated environment variable triple-checked that it was there)
It seems to fail on precompiling assets during the push to 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 <top (required)>'
...( rest of the long stacktrace with little of interest here)
the error is being raised when "devise_for" is run in the routes directory. relevant line:
MyApp::Application.routes.draw do
devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout'}
The relevant line in the actual devise gem is:
raise_no_secret_key unless Devise.secret_key
So it really is just checking if the secret_key got set.
just to confirm... I checked the heroku config, and I did in fact put a secret key into the environment under that name.
DEVISE_SECRET_KEY: 3f844454bee...(more here)
RAILS_SECRET_KEY_BASE: 04bf569d4e...(more here)
because it's in a rake task instead of the app - I'm guessing that's why it can't get to the ENV???
any ideas on where I might begin looking for a solution?
You're wanting to use a config var before (at compile time) it's actually made available to your app (at slug compilation time).
Try switching on the Heroku Labs: user-env-compile
I suspect it will solve the problem.
If it's breaking at compile time you need to enable user-env-compile, heroku labs:enable user-env-compile
to make the environment available when the application boots to compile the assets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With