home_controller.rb:
class HomeController < ApplicationController
def index
@title = "tags"
@posts = Post.tag_counts.collect do |tag|
Post.tagged_with(tag).first
end
@posts.flatten.uniq
@posts = @posts.paginate :page => params[:page], :per_page => 8
end
end
index.html.erb:
<%- for post in @posts -%>
<%- post.tags.each do |t| -%>
<%= link_to t.name, tag_path(t) %>
<%- end -%>
<%= link_to post.title, post %>
<%- if post.comments.empty? -%>
<% else %>
<%= link_to pluralize(post.comments.count, 'reply'), :controller => 'posts', :action => 'show', :id => post %>
<%- end -%>
<%= timeago(post.updated_at) %>
<%- end -%>
<%= will_paginate @posts, :previous_label => '<', :next_label => '>' %>
This view's purpose is to show the latest post of each tag. The updated_at timestamp of a post is updated each time that post is commented on.
it's displaying posts with this ordering:
tag id = 1
tag id = 2
tag id = 3
...
Can anyone tell me why the code above displays the posts in the order in which their tags were created?