:
@posts_by_month = Post.find(:all, :order => "created_at DESC").group_by { |post| post.created_at.beginning_of_month }
, , posts/_post_archive.html.erb:
<div id="post-archive">
<% @posts_by_month.each do |month, posts| %>
<h4><%= "#{month.strftime('%B %Y')} (#{posts.count}):" %></h4>
<ul>
<% for post in posts %>
<li><%= link_to post.title, post %></li>
<% end %>
</ul>
<% end %>
</div>
<%= render :partial => "posts/post_archive" %>
UPDATE:
:
def by_year_and_month
@posts = Post.where("YEAR(created_at) = ? AND MONTH(created_at) = ? ", params[:year], params[:month]).order("created_at DESC")
end
routes.rb:
match 'posts/by_year_and_month/:year/:month' => 'posts#by_year_and_month', :as=> :posts_by_year_and_month
posts/_posts_archive.html.erb:
<h4><%= link_to "#{month.strftime('%B %Y')} (#{posts.count}):", posts_by_year_and_month_path(:year=> month.year, :month => month.month) %></h4>