tangosource/knowledge_base

View on GitHub
app/models/document.rb

Summary

Maintainability
A
0 mins
Test Coverage
class Document < ActiveRecord::Base
  validates_presence_of :title
  acts_as_taggable
  acts_as_taggable_on :tag_list

  scope :search, -> q { where('title ILIKE ?', "%#{q}%") }
  scope :recent_ones, -> { order('created_at DESC').limit(10) }

  class << self
    def tags
      tag_counts.map do |tag|
        tag.name
      end
    end

    def popular_tags
      tag_counts_on(:tags, limit: 10, order: 'count desc')
    end
  end
end