2

This works:

production:
  adapter: mysql2
  encoding: utf8
  host: localhost
  database: myapp
  username: myapp
  password: jksdfUIJsdf

Then on terminal touch tmp/restart.txt.

This does not work:

production:
  adapter: mysql2
  encoding: utf8
  host: localhost
  database: myapp
  username: myapp
  password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>

Then on terminal

export MYAPP_DATABASE_PASSWORD=jksdfUIJsdf
touch tmp/restart.txt

So if I set the password as plaintext in database.yml file then my application works properly but if I set the password as environment variable with export command, then my application does not work because it gives error password missing. I am using mysql database. How to solve this?

1
  • What happens if you do 'puts ENV['MYAPP_DATABASE_PASSWORD']' in the rails console? Commented Apr 13, 2018 at 10:17

2 Answers 2

2

When you touch tmp/restart.txt, you're not starting a new Rails server, you're just telling the existing server to reload itself. The existing server will still have the environment it started with, and will never see any environment variables you set after that time.

Sign up to request clarification or add additional context in comments.

Comments

0

For Rails app configuration, I use figaro gem.

Add the below line to your Gemfile and do bundle.

gem "figaro"

After that run the below command:

bundle exec figaro install

This will create config/application.yml and also will add it to the .gitignore file.

Now inside config/application.yml enter the credentials.

# config/application.yml

MYAPP_DATABASE_PASSWORD: "2954"

Visit the Github page for more info.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.