Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to conditionally assign ActionController::Base.session in rails 2.3.3
    primarykey
    data
    text
    <p>I have a rails app that has the following content in the config/initializers/session_store.rb file:</p> <pre><code>ActionController::Base.session = { :key =&gt; '_app_session', :secret =&gt; 'a really long string here', :expire_after =&gt; 2.minutes } ActionController::Base.session_store = :active_record_store </code></pre> <p>So during normal operations we are seeing ActiveRecord objects created in the database for each session. The issue is that we don't always want to create a session for requests - we'd like to be able to turn off session creation for automated requests. We are seeing thousands of session records in the database, one for each automated request. Prior to rails 2.3.3, the following was possible:</p> <pre><code>class ApplicationController &lt; ActionController::Base session :off ... end </code></pre> <p>but now in rails 2.3.3 "session :off" has been deprecated because sessions are now lazy-loaded - if you don't use them, they are not created. The problem seems to be that the session object is always assigned in the sessionstore.rb file, and therefore always created. If I remove the session assignment block from the config file, then no session records appear after an automated request. My question is, how can I move the configuration assignments to the session hash out of session_store.rb and into the ApplicationController class (or elsewhere) where the session can be conditionally assigned only if a request is not automated? I'm concerned that the session config data may be needed before the controller handler is executed. Where would I put the assignment of the session key values?</p> <p>Thanks in advance for any help.</p>
    singulars
    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.
    plurals
    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