Although the correct answer has been chosen; I like to add other options.
Scenario: Lets say you are creating a blog and want to have simple authentication. In your post_controller.rb you would add the following:
http_basic_authenticate_with name: ENV["BLOG_USERNAME"],password: ENV["BLOG_PASSWORD"],except: [:show]
In order to communicate with these variables 'securely', choose an option:
Option 1
Create application.yml file inside config folder; where you would add your configuration (username and password), for example:
BLOG_USERNAME: "admin"
BLOG_PASSWORD: "12345"
Now, since application.yml includes sensitive information, we want Git to ignore that file. Therefore add the following to .gitignore file: /config/application.yml
Now we need to load these variables by adding the following line to application.rb file:
ENV.update YAML.load(File.read(File.expand_path('../application.yml', __FILE__)))
Option 2 Use Figaro gem
- In your
Gemfile add gem "figaro", run bundle install and also runfigaro install.
Figaro will create config/application.yml file and adds it to your .gitignore.
- Now add your own configuration to this file similar to step 1 above also follow step 3 and you're done!
Check Figaro's documentation for more details.