Module: Authlogic::Session::Persistence::ClassMethods

Defined in:
lib/authlogic/session/persistence.rb

Instance Method Summary collapse

Instance Method Details

#find(id = nil, priority_record = nil) ⇒ Object

This is how you persist a session. This finds the record for the current session using a variety of methods. It basically tries to “log in” the user without the user having to explicitly log in. Check out the other Authlogic::Session modules for more information.

The best way to use this method is something like:

helper_method :current_user_session, :current_user

def current_user_session
  return @current_user_session if defined?(@current_user_session)
  @current_user_session = UserSession.find
end

def current_user
  return @current_user if defined?(@current_user)
  @current_user = current_user_session && current_user_session.user
end

Also, this method accepts a single parameter as the id, to find session that you marked with an id:

UserSession.find(:secure)

See the id method for more information on ids.



36
37
38
39
40
41
42
43
44
# File 'lib/authlogic/session/persistence.rb', line 36

def find(id = nil, priority_record = nil)
  session = new({:priority_record => priority_record}, id)
  session.priority_record = priority_record
  if session.persisting?
    session
  else
    nil
  end
end