我希望删除任何重复的标签正在显示,并有10个标签在索引页面上显示的最大数量。对我该怎么做有什么建议吗?
/控制器/标签控制器
class TagsController < ApplicationController
def show
@tag = Tag.limit(10).all
@tag = Tag.find(params[:id])
@articles = @tag.articles
end
end
endmodel/tag.rb
class Tag < ActiveRecord::Base
validates :name, :uniqueness => true
#default_scope :order => 'created_at DESC'
has_many :taggings, :dependent => :destroy
has_many :articles, :through => :taggings
end发布于 2011-05-25 18:19:22
要避免重复并按发布日期排序,请在标记模型中执行以下操作:
validates :name, :uniqueness => true
default_scope :order => 'created_at DESC'要获取控制器中的前十个标记:
@tags = Tag.limit(10).all瞧!
https://stackoverflow.com/questions/6021621
复制相似问题