title: Group and sort blog posts by date in Rails
body: <p>I've searched all over web and have not found the answer. I'm trying to have a very standard archive option for my blog based on date. A request to url blog.com/archive/2009 shows all posts in 2009, blog.com/archive/2009/11 shows all posts in November 2009 etc. I found two different of code but not very helpful to me.</p>
  
  <pre><code>def display_by_date
   year = params[:year]
   month = params[:month]
   day = params[:day]
   day = '0'+day if day &amp;&amp; day.size == 1
   @day = day
   if (year &amp;&amp; month &amp;&amp; day)
     render(:template =&gt; "blog/#{year}/#{month}/#{date}")
   elsif year
    render(:template =&gt; "blog/#{year}/list")
   end
  end
  
  def archive
   year = params[:year]
   month = params[:month]
   day = params[:day]
   day = '0'+day if day &amp;&amp; day.size == 1
   if (year &amp;&amp; month &amp;&amp; day)
     @posts_by_month = Blog.find(:all, :conditions =&gt; ["year is?", year])
   else
     @posts_by_month = Blog.find(:all).group_by { |post| post.created_at.strftime("%B") }
   end
  end
  </code></pre>
  
  <p>Any help is appreciated.</p>