I am developing a Rails 4 app using the Active Admin gem for the administration back end. Active Admin in turn uses Devise for user authentication. Now, when I try to deploy
As per changelog:
Devise will use the secret_key_base on Rails 4+ applications as its secret_key. You can change this and use your own secret by changing the devise.rb initializer.
I went to config/secrets.yml
and changed the production
value.
Before:
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
After:
production:
secret_key_base: string of charaters
Of course, that should be set to the environment variable, which I will set later, but this at least got it running. I got my string by using bundle exec rake secret
.
What worked for me on Rails 4.1 and Devise 3.2.4 is in config/initializers/devise.rb
:
config.secret_key = ENV['DEVISE_SECRET_KEY'] if Rails.env.production?
I solve my initializer problem with this ugly approach:
config.secret_key = 'some1234keyq23' if Rails.env == 'production'
in config/initializers/devise.rb It now works in production as well as in development !
Trying to give a somewhat more complete answer to the ones above: As mentioned in the devise_auth_token gem's documentation
...Additionally, you can configure other aspects of devise by manually creating the traditional devise.rb file at
config/initializers/devise.rb
. Here are some examples of what you can do in this file:
Devise.setup do |config|
# The e-mail address that mail will appear to be sent from
# If absent, mail is sent from "please-change-me-at-config-initializers-devise@example.com"
config.mailer_sender = "support@myapp.com"
# If using rails-api, you may want to tell devise to not use ActionDispatch::Flash
# middleware b/c rails-api does not include it.
# See: http://stackoverflow.com/q/19600905/806956
config.navigational_formats = [:json] end
I had the same problem, and like metioned here, I created the devise initializer, and add the config.secret_key = ENV['DEVISE_SECRET_KEY']
line to it.