ENVhash is available to you everywhere — views, controllers, models,
rails console, rake tasks, etc. The keys in the hash are the names of any environment variables that exist on the computer you're using, and the values are the contents of the variables.
zebrathat had a value of
giraffe, this is how you would access it from within Rails:
If you realize you've made an error on any of the following steps, just type in
cd ~/workspaceand hit enter. That should get you back to the starting point.
cd ~and hit enter. This command should take you to the home folder of your workspace.
touch .bash_profileand hit enter. This command creates a hidden file called
.bash_profilein your home folder.
ls -aand hit enter. You'll see a list of all the files in your current directory, including hidden files (the ones whose names start with a
.bash_profileand click it. The file should open up in your editor.
=, and the value on the right.
=, and don't forget the
exportkeyword at the beginning of the line.
cd ~/workspaceto go back to your main folder, or just close that tab.
If you ever need to reopen your bash profile (for example to add additional environment variables), type
cd ~, hit enter, then type
ls -a, hit enter and click on the file to open it.
.bash_profilefile become key-value pairs in the
ENVhash. For example, to access this sensitive info, in a NEW Terminal tab (it won't work in old tabs) we can open a
rails consoleand type in:
gem "dotenv-rails"to your
.gitignorefile, make sure that there's a line somewhere with
.env. Then add your secrets to it; for example,
/.env*is included in the
.gitignorefile, this file doesn't exist as far as git is concerned; so it's safe to put your secrets in it.