Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't had to do this myself, and I'm not sure exactly why somebody might need to do this. </p> <p>Looking through the source code I can see that there might be a way of doing this.</p> <p>In the Authlogic::Session::Persistence Module there is a find method. You can call this method using UserSession.find and it appears to have the ability to search based on session_id</p> <pre><code> # 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 &amp;&amp; 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. def find(id = nil, priority_record = nil) session = new({:priority_record =&gt; priority_record}, id) session.priority_record = priority_record if session.persisting? session else nil end end end </code></pre> <p>The documentation for that method refers to the Authlogic::Session class.</p> <p>In Authlogic::Session::Session::Config it says that the session key can be a cookie key, a string, or a symbol.</p> <pre><code> module Config # Works exactly like cookie_key, but for sessions. See cookie_key for more info. # # * &lt;tt&gt;Default:&lt;/tt&gt; cookie_key # * &lt;tt&gt;Accepts:&lt;/tt&gt; Symbol or String def session_key(value = nil) rw_config(:session_key, value, cookie_key) end alias_method :session_key=, :session_key end </code></pre> <p>So, in the method that follows, which tries to find the current session, we can see that if the record_id is not nil then it looks up the session using that key.</p> <pre><code> def persist_by_session persistence_token, record_id = session_credentials if !persistence_token.nil? # Allow finding by persistence token, because when records are created the session is maintained in a before_save, when there is no id. # This is done for performance reasons and to save on queries. record = record_id.nil? ? search_for_record("find_by_persistence_token", persistence_token) : search_for_record("find_by_#{klass.primary_key}", record_id) self.unauthorized_record = record if record &amp;&amp; record.persistence_token == persistence_token valid? else false end end </code></pre> <p>record_id is created with the session_credentials method. Which seems to build a session key based on the key provided to the controller</p> <pre><code> def session_credentials [controller.session[session_key], controller.session["#{session_key}_#{klass.primary_key}"]].compact end def session_key build_key(self.class.session_key) end </code></pre> <p>I gathered most of this by browsing through the source at <a href="http://github.com/binarylogic/authlogic" rel="nofollow noreferrer">Github</a>. If you need more help, that may be the best place to start looking.</p> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload