0

I'm confused about how to properly use figaro with Rails 4.2. So in application.yml (which is checked into .gitignore), I have this:

secret_key_base: 123456

And then in secrets.yml, I have this:

development:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

The gem should be handling the ENV part of setting the credentials, according to everything I've read. Why is this not working?



EDIT 1: In application.yml I have: mandrill_user_name: email@example.com and mandrill_password: 1234567890

And in development.rb I have:

config.action_mailer.default_url_options = { :host => "localhost:3000" }

config.action_mailer.smtp_settings = {
  address: "smtp.mandrillapp.com",
  port: 587,
  domain: "localhost:3000",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["mandrill_user_name"],
  password: ENV["mandrill_password"]
}

Shouldn't application.yml be taking care of this?

calyxofheld
  • 1,538
  • 3
  • 24
  • 62

1 Answers1

1

If is redundant to have the variable in the secrets.yml file and the application.yml file. I.e. use the application.yml file ONLY to declare ENV Vars.

So long as it is in the apllication.yml file you can call it throughout your rails app just like you are doing:

ENV["SECRET_KEY_BASE"]

Varialbles stored in the secrets.yml file are called via

Rails.application.secrets.SECRET_KEY_BASE
blnc
  • 4,384
  • 1
  • 28
  • 42
  • I'm sorry, but I'm severely confused. It doesn't work, so I think I'm doing something wrong. I have `secret_key_base: 123456` in application.yml, and then I call it in development.rb with `ENV["secret_key_base"]`. Nothing happens. Also, if it's redundant to use secrets.yml, why does this answer say otherwise?: http://stackoverflow.com/a/26569119/2009652 – calyxofheld Jul 08 '15 at 04:23
  • 1
    What do you mean nothing happens? – blnc Jul 08 '15 at 04:54
  • I have `mandrill_password: 1234567890` set in application.yml and `password: ENV["mandrill_password"]` set in the action mailer config in development.rb. The expected action is that a user can put their email into a form I've created, and hit submit to sign up. This then sends them an email. Everything is set up, and I'm successful at getting this to work just fine until I try storing the mandrill credentials in ENV variables. So when I say "nothing happens" in this case I mean I get no email. In other cases - like storing the application key in an ENV variable - it causes $rails s to not load – calyxofheld Jul 08 '15 at 05:02
  • 1
    can you add your development.rb action mailer config code to your post – blnc Jul 08 '15 at 05:07
  • also run the following commands in terminal: "spring stop" then "spring start" – blnc Jul 08 '15 at 05:15
  • 1
    1) is figaro in your Gemfile? 2) did you restart spring? 3) did you restart your webserver after updating your application.yml file? – – blnc Jul 08 '15 at 15:48
  • I'm certain that I had the first two done, but probably forgot to restart the webserver. I'm not entirely certain how, but it works now. What does spring do? – calyxofheld Jul 08 '15 at 19:17
  • Also, what's the point of secrets.yml if figaro does it better? – calyxofheld Jul 08 '15 at 19:52
  • And is it safe to keep development and test env secrets in the repository? – calyxofheld Jul 08 '15 at 20:16
  • 1
    1) spring auto loads the environment so you can perform tasks faster (bin/rake, bin/rails). 2) the file becomes relatively worthless, just leave it there the way it is generated when you create the project or you will run into error when committing to heroku 3) it's best practice not to store them in the repo 4) if this solved your problems mark the answer correct – blnc Jul 09 '15 at 00:47