2011-05-16 4 views
0

표시되는 중복 태그를 제거하고 인덱스 페이지에 최대 10 개의 태그가 표시되도록합니다. 내가 이것을 어떻게 할 수 있을지에 대한 제안?레일 3 - 기사 태그 제한

/컨트롤러/tags_controller

class TagsController < ApplicationController 
def show 
@tag = Tag.limit(10).all 
@tag = Tag.find(params[:id]) 
@articles = @tag.articles 
end 
end 
end 

모델/tag.rb avoir으로

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 

답변

1

가 복제 및 태그 모델, 출판 날짜별로 주문 :

validates :name, :uniqueness => true 
default_scope :order => 'created_at DESC' 

으로 컨트롤러에 10 개의 첫 번째 태그를 가져옵니다.

@tags = Tag.limit(10).all 

Voila!

+0

고유성 및 기타 기능. * @ tags = Tag.limit (10) .all *은 효과가 없습니다! – ubique