<pre><tt><spanstyle="font-style: italic"><spanstyle="color: #9A1900"># Set to one of [:active_record_store, :drb_store, :mem_cache_store, :cookie_store]</span></span>
<h3id="_accessing_the_session">4.1. Accessing the Session</h3>
<h3id="_accessing_the_session">4.1. Accessing the Session</h3>
<divclass="paragraph"><p>In your controller you can access the session through the <tt>session</tt> instance method.</p></div>
<divclass="admonitionblock">
<table><tr>
<tdclass="icon">
<imgsrc="./images/icons/note.png"alt="Note"/>
</td>
<tdclass="content">Sessions are lazily loaded. If you don’t access sessions in your action’s code, they will not be loaded. Hence you will never need to disable sessions, just not accessing them will do the job.</td>
<tdclass="content">Sessions are lazily loaded. If you don’t access sessions in your action’s code, they will not be loaded. Hence you will never need to disable sessions, just not accessing them will do the job.</td>
</tr></table>
</div>
<divclass="paragraph"><p>Session values are stored using key/value pairs like a hash:</p></div>
<divclass="paragraph"><p>To reset the entire session, use <tt>reset_session</tt>.</p></div>
<h3id="_the_flash">4.2. The flash</h3>
<h3id="_the_flash">4.2. The flash</h3>
<divclass="paragraph"><p>The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for storing error messages etc. It is accessed in much the same way as the session, like a hash. Let’s use the act of logging out as an example. The controller can send a message which will be displayed to the user on the next request:</p></div>
<divclass="listingblock">
<divclass="content"><!-- Generator: GNU source-highlight 2.9
<divclass="paragraph"><p>By default, adding values to the flash will make them available to the next request, but sometimes you may want to access those values in the same request. For example, if the <tt>create</tt> action fails to save a resource and you render the <tt>new</tt> template directly, that’s not going to result in a new request, but you may still want to display a message using the flash. To do this, you can use <tt>flash.now</tt> in the same way you use the normal <tt>flash</tt>:</p></div>
<divclass="listingblock">
<divclass="content"><!-- Generator: GNU source-highlight 2.9