ホーム > ブログ > Ruby on Rails BASIC認証

Ruby on Rails BASIC認証

Ruby on RailsでBASIC認証をかけるには、
authenticate_or_request_with_http_basicを使用します。

app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  before_filter :authenticate

  private
  def authenticate
    authenticate_or_request_with_http_basic do |username, password|
	  username == 'ユーザー名' && password == 'パスワード'
    end
  end
end

※「ユーザー名」、「パスワード」の部分は適切に設定してください。


環境
Rails 2.3.5
前の記事 «
次の記事 »