Sha256: 5cfcfb03ba9de18fb16f7ecf5b0455bcebd8f10eeb3240458c6db5fb112b4c31

Contents?: true

Size: 923 Bytes

Versions: 5

Compression:

Stored size: 923 Bytes

Contents

class Tag < ActiveRecord::Base
  validates_presence_of :slug
  validates_format_of :slug, :with => /^[0-9a-zA-z\-]+$/
  
  has_many :taggings, :dependent => :destroy
  has_many :tags, :through => :articles
  
  def weight
    Tagging.count :conditions => "tag_id = #{self.id}"
  end
  
  def to_param
    self.slug
  end
  
  def page_articles page=nil
    Article.paginate :page => page,
                     :joins => :taggings,
                     :order => 'articles.created_at DESC',
                     :conditions => ['taggings.tag_id=?', self.id],
                     :per_page      => Hubbub::Config[:items_per_page] || 10
  end
  
  def feed_articles
    Article.find :all,
                 :joins => :taggings,
                 :order => 'articles.created_at DESC',
                 :conditions => ['taggings.tag_id=?', self.id],
                 :limit      => Hubbub::Config[:items_per_feed] || 5
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hubbub-0.0.11 lib/app/models/tag.rb
hubbub-0.0.10 lib/app/models/tag.rb
hubbub-0.0.9 lib/app/models/tag.rb
hubbub-0.0.8 lib/app/models/tag.rb
hubbub-0.0.6 lib/app/models/tag.rb