Once we deploy our staging application and it's accessible on the Internet, we'll want to restrict access to it. This will protect us from any users accidently coming across it or search engines crawling and indexing it.
In this recipe, we will learn how to add basic HTTP authentication to a Rails application.
For this recipe, we'll need an existing Rails application to modify. If we don't have one, we can use the application that we set up in Chapter 1, Getting Started with Heroku.
Every Rails application has a configuration file specific to each environment that it runs in. Each of these config files can be found in the config/environments
folder. Let's perform the following steps:
To start, we'll want to create a new environment file for staging. Let's do this now by creating a
staging.rb
file in theconfig/environments
folder.In this file, we'll add the following code:
# Based on production defaults require Rails.root.join('config...