tags_controller.rb:
def index
@title = "tags"
@posts = Post.tag_counts.collect do |tag|
Post.tagged_with(tag).first(:order => "updated_at DESC")
end
@posts.uniq!
end
标记/ index.html.rb:
<%= render 'latest' %>
_latest.html.erb:
<%- for post in @posts -%>
<%- post.tags.each do |t| -%>
<%= link_to t.name, tag_path(t) %>
<%- end -%>
<%- end -%>
我的目标是只展示最新的10个帖子,每个帖子都有一个独特的标签。上面的当前代码显示了唯一的标签,但超过10.有人可以帮忙吗?
答案 0 :(得分:0)
没关系。我刚用will_paginate来解决这个问题。