Book Image

Heroku Cookbook

By : Mike Coutermarsh
Book Image

Heroku Cookbook

By: Mike Coutermarsh

Overview of this book

Heroku is a Platform as a Service that enables developers to rapidly deploy and scale their web applications. Heroku is designed for developer happiness, freeing developers from doing system administrative tasks such as configuring servers and setting up load balancers. Developers are able to focus on what they do best, building web applications, while leaving the details of deployment and scaling to the experts at Heroku. This practical guide is packed with step-by-step solutions to problems faced by every production-level web application hosted on Heroku. You'll quickly get comfortable with managing your Heroku applications from the command line and then learn everything you need to know to deploy and administer production-level web applications.
Table of Contents (17 chapters)
Heroku Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Password protection for a Rails app


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.

Getting ready

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.

How to do it…

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:

  1. 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 the config/environments folder.

  2. In this file, we'll add the following code:

    # Based on production defaults
    require Rails.root.join('config...