Digest Authentication in Ruby on Rails

Use authenticate_or_request_with_http_digest:

class ApplicationController < ActionController::Base
  # ...

  before_filter :authenticate_user

  REALM = Rails.application.class.parent_name

  private

  def authenticate_user
    user = authenticate_or_request_with_http_digest(REALM) do |name|
      Digest::MD5.hexdigest [name, REALM, 'secret_password'].join ':'
    end

    unless user
      render file: 'public/401.html', status: :unauthorized, layout: false
    end
  end
end