這是我的設置:Authlogic - 如何檢查,如果用戶登錄了
user.rb
acts_as_authentic do |c|
c.logged_in_timeout(1.minutes)
end
user_session.rb
def to_key
new_record? ? nil : [ self.send(self.class.primary_key) ]
end
self.logout_on_timeout = true
application_controller.rb
helper_method :current_user_session, :current_user
private
def current_user_session
logger.debug "ApplicationController::current_user_session"
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
logger.debug "ApplicationController::current_user"
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user
end
def require_user
logger.debug "ApplicationController::require_user"
unless current_user
#store_location
flash[:warning] = "You must be logged in to access this page"
#redirect_to new_user_session_url
redirect_to root_url
return false
end
end
def require_no_user
logger.debug "ApplicationController::require_no_user"
if current_user
#store_location
flash[:warning] = "You must be logged out to access this page"
redirect_to account_url
return false
end
end
但是當我加載我的網頁時,我會得到的錯誤
undefined method `logged_out?' for #<User:0x00000103ee8348>
我嘗試讀取Authlogic的官方頁面GitHub的,但我仍然不知道,我錯過......誰能給我修復它小費了嗎?
非常感謝提前!
爲了解決未定義的方法「logged_out」,只有「last_request_at」是必要的。 –