2011-11-15 43 views
3

我在下面:The infamous RoR blog tutorial security section回報率:未定義的方法`http_basic_authenticate_with」

而且從試圖達到特定的相關頁面時,一些奇怪的原因,我得到一個:

undefined method 'http_basic_authenticate_with' for PostsController:Class錯誤

我「M使用:

  • 的Rails 3.0.9,
  • RubyGems的1.8.11,
  • 紅寶石1.9.2p290

任何想法可能會導致這樣或者一個特定的寶石,其缺什麼?控制器代碼的

部分:

class PostsController < ApplicationController 
    http_basic_authenticate_with :name => "dhh", :password => "secret", 
           :except => :index 
# GET /posts 
# GET /posts.xml 
def index 
    @posts = Post.all 

    respond_to do |format| 
    format.html # index.html.erb 
    format.xml { render :xml => @posts } 
    format.json { render :json => @posts } 
    end 
end 
+0

您可以發佈您的控制器代碼(或其中的部分)? – Nick

+0

剛剛更新了文章 –

+0

請記住,HTTP Auth-Basic是一個非常不安全的選項,您的密碼將通過網絡發送明文,用於每個請求。 – Jacco

回答

4

你可以試試這個鋼軌3及更早的版本:

class ApplicationController < ActionController::Base 
USER, PASSWORD = 'dhh', 'secret' 

before_filter :authentication_check, :except => :index 

... 

private 
    def authentication_check 
    authenticate_or_request_with_http_basic do |user, password| 
    user == USER && password == PASSWORD 
    end 
    end 
end 
+0

我用rails 3.0.9,這個答案幫我,謝謝。 – HelloWorld

相關問題