Rails | 10月 6th, 2008
デフォルトで用意されている Basic 認証の仕組みの使い方。ユーザ名 chihaya , パスワード password72 とすると、以下のようにする。
class ApplicationController < ActionController::Base before_filter :basic_authentication # テストだけ使うBasic認証 protected def basic_authentication authenticate_or_request_with_http_basic do |user, pass| [user, pass] == ['chihaya', 'password72'] end end end
特定のActionはBasic認証かけたくないならば、skip_before_filter を使う。
class NanohaController < ApplicationController skip_before_filter :basic_authentication, :only => [:show] def show end end




