This is my setup:
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
But when I load my page, I will get the error
undefined method `logged_out?' for #<User:0x00000103ee8348>
I try to read the official GitHub page of Authlogic, but I still don’t know, what I miss… Could anyone give me a tip for fix it?
Many thanks in advance!
I was having the exact same problem, and it boiled down to the fact I didn’t have all of the necessary columns in my User model.
My original User model (from
db/schema.rb) was pretty minimalistic:However, I added the column
t.datetime :last_requested_atto my model, as well as a few others that may or may not be needed. My final User model looks like:After adding in the other columns, I no longer get the
undefined method 'logged_out?'...error.Good luck!
(reference/more info: http://www.michaelhamrah.com/blog/2009/05/authlogic-and-openid-on-rails/ — search in the page for
logged_out?, the explanation was about 3/4 of the way down the post.)