title: display posts by month/year ruby
body: <p>Not sure where to start with this so here goes.. I am building a small blog in which the date of each  post is displayed, overtime there will be many blog posts per month, for which i would like to group together by the month it was published.</p>
  
  <p>I want to display it like this in the view</p>
  
  <pre><code>Archives
  
  January 2013
  February 2013
  March 2013
  etc
  </code></pre>
  
  <p>When i click on a given month the idea is it will take me to all the posts that where published within that month. </p>
  
  <p>So far I can group all the posts by month and year</p>
  
  <pre><code>@posts_by_month = Post.all.group_by { |post| post.created_at.strftime("%B %Y") }
  </code></pre>
  
  <p>In my view i then render like so</p>
  
  <pre><code>&lt;% @posts_by_month.each do |m| %&gt;
    &lt;%= m %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Which returns this in the view</p>
  
  <pre><code>["July 2013", [#&lt;Post id: 1, title: "Ruby News", comments: "dsfdsfdsfdsfdsfds", category_id: 1, user_id: 1, created_at: "2013-07-26 07:10:25", updated_at: "2013-07-26 07:19:27", photo_file_name: "pf-7.jpg", photo_content_type: "image/jpeg", photo_file_size: 162495, photo_updated_at: "2013-07-26 07:19:26"&gt;]] 
  </code></pre>
  
  <p>So at the moment i have a hash where the month/year is the key and then all my posts in an array, is that correct?</p>
  
  <p>All i want to display is the Month/Year and then click that month to be taken to all the posts for that month</p>
  
  <p>Any help appreciated</p>
  
  <p>EDIT</p>
  
  <p>ok silly me, forgot my basics on key/value pairing, i have got just the date to display</p>
  
  <pre><code>&lt;% @posts_by_month.each do |m,p| %&gt;
    &lt;%= link_to m %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Now i just need to be able to click the link to see all posts for that month</p>