Skip to content

Instantly share code, notes, and snippets.

@rubyrider
Created December 28, 2014 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubyrider/0a345c64e952dc748cdf to your computer and use it in GitHub Desktop.
Save rubyrider/0a345c64e952dc748cdf to your computer and use it in GitHub Desktop.
Sort Post by date!
# 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