Reputation: 680
I've just switched to using the Figaro gem v1.0.0 with Rails 4.1.6. Since deleting my secrets.yml file I now get the error:
Unexpected error while processing request: Missing secret_key_base
for 'development' environment, set this value in config/secrets.yml
Do i still need the secrets.yml file - isn't this the job of Figaro's application.yml file?
My application.yml file is like
development:
secret_key_base: 56....
Upvotes: 2
Views: 2916
Reputation: 680
Looking into the Railties gem at https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb you can see the secrets method defined which includes a fallback for secret_key_base
def secrets #:nodoc:
@secrets ||= begin
secrets = ActiveSupport::OrderedOptions.new
yaml = config.paths["config/secrets"].first
if File.exist?(yaml)
require "erb"
all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {}
env_secrets = all_secrets[Rails.env]
secrets.merge!(env_secrets.symbolize_keys) if env_secrets
end
# Fallback to config.secret_key_base if secrets.secret_key_base isn't set
secrets.secret_key_base ||= config.secret_key_base
secrets
end
end
In config/application.rb adding the following resolves the issue
config.secret_key_base = Figaro.env.secret_key_base
Upvotes: 10
Reputation: 2520
I was just informed that as of Rails 4.1.x, config/secrets.yml
does need to be uploaded to heroku. Rails will no longer look directly at its ENV in order to find its secret_key_base
.
So secrets.yml
needs to come off of the .gitignore
file, and your project would need to be recommited and re-pushed to heroku.
(secrets.yml
would still get its values from heroku's ENV, which would still be loaded up via Figaro the same way as before - figaro heroku:set -e production
. Use heroku config
to get a nice quick look at your ENV variables to confirm they are there)
Upvotes: 0
Reputation: 894
I have never used Figaro gem but try these, create the config/secret.yml file and inside write:
development:
secret_key_base: <%= ENV['secret_key_base'] %>
Upvotes: 0