| 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

3 comments

  1. とおりすがり

    2月 23rd, 2009

    グッジョブ!

  2. GarykPatton

    6月 17th, 2009

    I have been looking looking around for this kind of information. Will you post some more in future? I’ll be grateful if you will.

  3. ちゅう

    6月 18th, 2009

    Yes, I will post related to this post !
    Please check my weblog. Thank you.

Trackbacks and Pingbacks

Leave a Comment


download the hurt locker  
UA-682965-1