Created
August 4, 2008 15:03
-
-
Save mislav/3905 to your computer and use it in GitHub Desktop.
Group paginated messages by day
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
<h1>Last activity</h1> | |
<% for day, messages in @messages_by_day -%> | |
<h2><%= day %></h2> | |
<ol> | |
<%- for message in messages -%> | |
<li><%= link_to message.title, message %></li> | |
<%- end -%> | |
</ol> | |
<% end -%> | |
<%= will_paginate @messages %> |
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
# fetch last 30 messages | |
@messages = Message.paginate :page => params[:page], :order => "created_at DESC" | |
# group them by date | |
@messages_by_day = @messages.group_by { |message| message.created_at.to_date } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment