Created
December 28, 2014 00:54
-
-
Save rubyrider/0a345c64e952dc748cdf to your computer and use it in GitHub Desktop.
Sort Post by date!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in controller#action | |
@posts = Post.all.group_by(&:created_at) | |
# view | |
<% @posts.each do |date, posts | %> | |
<h2><%= date.strftime("#{date.day.ordinalize} %B,%Y") %></h2> | |
<tr> | |
<% posts.each do | post | %> | |
<td><%= post.what_ever_column_you_need %></td> | |
<% end %> | |
</tr> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment