2011-08-06 47 views
1

好的,我從Pragmatic Bookshelf文本中學習R on R0 Agile Webdevelopment with Rails 4th ed。SessionsController中的NoMethodError#create

我在212頁,我得到這個錯誤.... NoMethodError in SessionsController#createapp/controllers/sessions_controller.rb:7:in 'create'

我出去拉我的鬍子在這裏,我已經花了幾天試圖跟蹤下來。這是創建代碼,這是指向...

def create 
    if user = User.authenticate(params[:name], params[:password]) 
    session[:user_id] = user.id 
    redirect_to admin_url 
    else 
    redirect_to login_url, :alert => "Invalid user/password combination" 
    end 
end 

任何古魯可以幫助嗎?

+1

您是否在用戶模型中定義了'authenticate'? – apneadiving

+0

什麼是第7行?它聲稱丟失了什麼方法? –

+0

好吧......休息一會兒後,我注意到我在我的模型中錯誤地命名了User.authenticate。問題解決了。 – thefonso

回答

1

聽起來像您需要在您的用戶模型(我的書上的第203頁)中使用以下內容。如果這不是問題,請提供您的用戶模型。

def User.authenticate(name, password) 
    if user = find_by_name(name) 
    if user.hashed_password == encrypt_password(password, user.salt) 
     user 
    end 
    end 
end 
相關問題