2

tags_controller.rb:显示最新的帖子全部来自独特的标签(Rails的3.0,Acts_As_Taggable_On)

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

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

相关问题