Skip to content

Instantly share code, notes, and snippets.

@taylor
Last active March 1, 2016 20:01
Show Gist options
  • Select an option

  • Save taylor/10000885 to your computer and use it in GitHub Desktop.

Select an option

Save taylor/10000885 to your computer and use it in GitHub Desktop.
initializers/devise.rb change for to support Devise secret_key as an environment variable.
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index cbe1fbd..358f9c3 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -5,6 +5,11 @@ Devise.setup do |config|
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
# config.secret_key = '13844ee05eb483442eef5ace6cd3a7ba60cf65bf0165dad57ed09150e6a1cb62913ca593bd68debb6235e79f04e5c587c
+ if Rails.env.production?
+ config.secret_key = ENV['DEVISE_SECRET_KEY']
+ else
+ config.secret_key = 'x' * 128
+ end
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer
@taylor

taylor commented Apr 6, 2014

Copy link
Copy Markdown
Author

This was to deal with a deploy to heroku complaining about Devise secret key:


-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       ** [Airbrake] Failure: Net::HTTPUnauthorized
       rake aborted!
       Devise.secret_key was not set. Please add the following to your Devise initializer:
       config.secret_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
       Please ensure you restarted your application after installing Devise or setting the key.

After updating the code to use the environment variable (DEVISE_SECRET_KEY) run heroku config:set DEVISE_SECRET_KEY=xxx --app blah

You can get a key by running rake secret

@Cponcax

Cponcax commented Mar 1, 2016

Copy link
Copy Markdown

You can improve the code: config.secret_key = ENV['DEVISE_SECRET_KEY'] if Rails.env.production?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment