Class: ActsAsTaggableOn::Tag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/acts_as_taggable_on/tag.rb

Overview

require_dependency ActsAsTaggableOn::Engine.config.root.join(‘lib’, ‘acts_as_taggable_on’, ‘tag.rb’).to_s

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_per_pageObject



15
16
17
# File 'app/models/acts_as_taggable_on/tag.rb', line 15

def default_per_page
  25
end


6
7
8
9
10
11
12
13
# File 'app/models/acts_as_taggable_on/tag.rb', line 6

def popular(limit = 20, type = nil)
  if type == nil
    ActsAsTaggableOn::Tag.most_used(limit)
  else
    klass = Object.const_get type
    klass.tag_counts.most_used(limit)
  end
end

Instance Method Details



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/acts_as_taggable_on/tag.rb', line 26

def related_tags(limit = 10)
  taggables = self.taggings.limit(10).to_a.collect{|t| t.taggable }.compact

  tagging_ids = taggables.map{|t| t.taggings.limit(10).map(&:id) }.flatten.uniq
  return [] if tagging_ids.blank?

  ActsAsTaggableOn::Tag.where("tags.id != '#{self.id}'")
    .joins(:taggings)
    .where({:taggings => {:id => tagging_ids }})
    .order("taggings_count DESC")
    .limit(limit)
end

#to_paramObject



21
22
23
# File 'app/models/acts_as_taggable_on/tag.rb', line 21

def to_param
  URI.escape(URI.escape(self.name), /[\/.?#]/)
end