Sha256: d40556223d5fea4676d0afbb801a12c4a3d1f891e1ab5b0773eef600a75b78ef

Contents?: true

Size: 718 Bytes

Versions: 2

Compression:

Stored size: 718 Bytes

Contents

module Answers
  class Question < ActiveRecord::Base

    acts_as_taggable_on :tags
    has_many :answers
    searchkick wordnet: true

    attr_writer :tag_ids
    
    def top_answer
      self.answers.first
    end
    
    # returns tags in order of most taggings to least taggings
    def self.tags
      self.tag_counts_on(:tags).sort_by(&:taggings_count).reverse
    end
    
    def self.tags_with_questions
      tags = self.tag_counts_on(:tags).limit(4).order("taggings_count DESC").all
      tags_with_questions = tags.map do |tag|
        {
          tag: tag,
          questions: Question.find(tag.taggings[0..3].map(&:taggable_id))
        }
      end
      
      tags_with_questions
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
answers-core-0.0.0.2 app/models/answers/question.rb
answers-core-0.0.0 app/models/answers/question.rb