Password protecting pages of Rails App

March 17, 2013 · Posted in Development 

Often it is needed to close a whole app or some pages of a Rails app in Beta mode. A simple and quick way is using http authentication. So users (beta testers, admin) can access a Rails app by entering a single username and password.

This example shows how to password protect the whole app in beta environment using a single login/password.

Modify ApplicationController. Change username and password to your own.

class ApplicationController < ActionController::Base
before_filter :authenticate if Rails.env.beta?
 
def authenticate
authenticate_or_request_with_http_basic('Administration') do |username, password|
username == 'admin' && password == 'password'
end
end
end

 

 

 

 

 

References:

* authenticate_or_request_with_http_basic
* Lock down a Rails 3 app on Nginx

Comments

  • http://maxivak.com/rails-best-practices/ Rails Best Practices : Max Ivak Personal Site

    [...] * Password protecting pages of Rails App [...]