Hi I have my rails app on heroku and github and am currently using a mailer in my app:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "myemail@gmail.com",
:password => "PasswordShouldGoHere",
:authentication => "plain",
:enable_starttls_auto => true
}
I don’t want my email and password to be visible on my github account, since people can just log in and steal my info. However, if I put a fake password, then my app will give me an error on heroku when the mailer is supposed to deliver. I know I can just push up the real email and password to heroku first and then edit it and put the fake password on my github account, but is there a better way?
Like other people said, you can achieve this security by using
ENVvariables. Here’s how to do it:Now, in production (Heroku), all you have to do is follow this guide. It basically amounts to opening your console and typing this:
In development, you can create a file inside the config/initializers folder with a suggestive name like
app_env_vars.rb. Inside it, place the following:To prevent this newly created file from being pushed into your source control, you should add it to your
.gitignore:However, there’s a problem because initializer files are only loaded after the environment, so there’s one last thing to do. Go to your
environment.rbfile and add the following before theYourapp::Application.initialize!:You’re done!
However, if you find all of this configuration a hassle, then I recommend using the Figaro gem. It does everything I described and more!