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個。任何人都可以幫忙嗎?