2

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 个。有人可以帮忙吗?

4

1 回答 1

0

没关系。我只是使用 will_paginate 来解决这个问题。

于 2010-09-16T19:27:24.460 回答