显示所有独特标签的最新帖子(Rails 3.0,Acts_As_Taggable_On)

时间:2010-09-08 22:09:04

标签: ruby-on-rails model controller ruby-on-rails-3 acts-as-taggable-on

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

1 个答案:

答案 0 :(得分:0)

没关系。我刚用will_paginate来解决这个问题。