<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: activerecord code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 23:26:30 GMT</pubDate>
    <description>DZone Snippets: activerecord code</description>
    <item>
      <title>Finding recent data in database</title>
      <link>http://snippets.dzone.com/posts/show/5341</link>
      <description>This shows how to find recent data from last hour, day, week, month, whatever&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Post &lt; ActiveRecord::Base&lt;br /&gt;  def self.find_latest(time = nil)&lt;br /&gt;    r = %w( hour day week month year )&lt;br /&gt;    if r.include?(time)&lt;br /&gt;      self.find :all, :conditions =&gt; ['created_at &gt; ?', 1.send(time).ago]&lt;br /&gt;    else&lt;br /&gt;      self.find :all&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Post.find_latest('day')&lt;br /&gt;Post.find_latest('week')&lt;br /&gt;Post.find_latest('year')&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 09 Apr 2008 20:34:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5341</guid>
      <author>ronin (Micha&#322; M)</author>
    </item>
  </channel>
</rss>
