Ruby on Rails simple authentication

project/app/controllers/application_controller.rg

class ApplicationController < ActionController::Base
protect_from_forgery

private

def authenticate
authenticate_or_request_with_http_basic do |user_name, password|
user_name == ‘admin’ && password == ‘password’
end
end
end

example usage: project/app/controllers/example_controller.rb

class TracksController < ApplicationController

before_filter :authenticate, :except => [:index, :show]

end

Leave a Reply

You must be logged in to post a comment.