【问题标题】:Show latest posts all from unique tags (Rails 3.0, Acts_As_Taggable_On)显示所有来自唯一标签的最新帖子(Rails 3.0,Acts_As_Taggable_On)
【发布时间】:2010-09-08 22:09:04
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多