Class: Cms::Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::Tag
- Extended by:
- DefaultAccessible
- Includes:
- Concerns::IgnoresPublishing
- Defined in:
- app/models/cms/tag.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
Returns the value of attribute size.
Class Method Summary collapse
-
.cloud(options = {}) ⇒ Object
Returns an array of tags with a size attribute This takes the same arguments as find, plus the additional ‘:sizes` option, which contols the number of sizes the tag cloud will have.
- .columns_for_index ⇒ Object
-
.counts ⇒ Array
Returns an array of tags with a #count attribute.
- .named(tag) ⇒ Object
Instance Method Summary collapse
Methods included from DefaultAccessible
non_permitted_params, permitted_params
Methods included from Concerns::IgnoresPublishing
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
10 11 12 |
# File 'app/models/cms/tag.rb', line 10 def size @size end |
Class Method Details
.cloud(options = {}) ⇒ Object
Returns an array of tags with a size attribute This takes the same arguments as find, plus the additional ‘:sizes` option, which contols the number of sizes the tag cloud will have. The default number of sizes is 5.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/cms/tag.rb', line 32 def self.cloud(={}) sizes = (.delete(:sizes) || 5) - 1 sizes = 1 if sizes < 1 = counts.limit(sizes) return [] if .blank? min = nil max = nil .each do |t| t.count = t.count.to_i min = t.count if (min.nil? || t.count < min) max = t.count if (max.nil? || t.count > min) end divisor = ((max - min) / sizes) + 1 .each do |t| t.size = ("%1.0f" % (t.count * 1.0 / divisor)).to_i end end |
.columns_for_index ⇒ Object
58 59 60 61 62 |
# File 'app/models/cms/tag.rb', line 58 def self.columns_for_index [{:label => "Name", :method => :name, :order => "name"}, {:label => "Usages", :method => :tagging_count}, {:label => "Updated On", :method => :updated_on_string, :order => "updated_at"}] end |
.counts ⇒ Array
Returns an array of tags with a #count attribute
21 22 23 24 25 26 |
# File 'app/models/cms/tag.rb', line 21 def self.counts() select("#{table_name}.id, #{table_name}.name, count(#{table_name}.id) as count") .joins(:taggings) .group("#{table_name}.id, #{table_name}.name") .order("count desc, #{table_name}.name") end |
.named(tag) ⇒ Object
14 15 16 |
# File 'app/models/cms/tag.rb', line 14 def self.named(tag) where(name: tag) end |
Instance Method Details
#render ⇒ Object
64 65 66 |
# File 'app/models/cms/tag.rb', line 64 def render @taggings = @content_block.taggings.paginate(:page => params[:page]) end |
#tagging_count ⇒ Object
54 55 56 |
# File 'app/models/cms/tag.rb', line 54 def tagging_count taggings.count end |