Ruby on Rails 3.2幫手沒有定義方法
我的sessions_controller.rb檢查'signed_in_person'是否已經有記錄的會話時繞過登錄。
我「signed_in_person」在session_helper.rb定義,但我得到一個錯誤:
Started POST "/sessions" for 50.241.102.227 at 2014-02-25 10:12:33 -0800
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"fFo4EM1MOHNO1Thic6qA/uapGj8pbiNaepKYF5Ge0Tw=", "session"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "com
mit"=>"Sign in"}
Person Load (0.1ms) SELECT `persons`.* FROM `persons` WHERE `persons`.`email` = '[email protected]' LIMIT 1
Completed 500 Internal Server Error in 66ms
NoMethodError (undefined method `sign_in_person' for #<SessionsController:0x00000004f7ace8>):
app/controllers/sessions_controller.rb:11:in `create'
從控制檯檢查時,該人是在數據庫表中。 我sessions_controller:
def create
if params[:session][:email].include? 'blah.com'
person = Person.find_by_email(params[:session][:email].downcase)
if person && person.authenticate(params[:session][:password])
sign_in_person person
redirect_back_or person
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
else
...
end
end
我sessions_helper:
module SessionsHelper
# For Persons
def sign_in_person(person)
cookies[:remember_token] = person.remember_token
self.current_person = person
end
def signed_in_person?
!current_person.nil?
end
...
任何想法,爲什麼我的sessions_helper是沒有幫助?
這並沒有改變錯誤,:(如果我添加,'包括SessionsHelper'給我的persons_controller錯誤消失了,那好嗎? – DDDD
@DDDD這真的很奇怪,因爲錯誤日誌說你試圖從'SessionsController'調用'sign_in_person' ..你是否也在'PersonsController'上使用過該方法? – raviolicode
不,但PersonsController是使用SessionsController – DDDD