<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: user_id code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 16:41:09 GMT</pubDate>
    <description>DZone Snippets: user_id code</description>
    <item>
      <title>A caching current user method call</title>
      <link>http://snippets.dzone.com/posts/show/4922</link>
      <description>A simple method that returns the current user and caches the result to reduce database hits.  This assumes you're storing user information in User and that the current user is identified by the session variable user_id.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class ApplicationController &lt; ActionController::Base&lt;br /&gt;  def current_user&lt;br /&gt;    session[:user_id] ? @current_user ||= User.find(session[:user_id]) : nil&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 24 Dec 2007 03:19:52 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4922</guid>
      <author>mgreenly (Michael Greenly)</author>
    </item>
  </channel>
</rss>
