Class: Answers::Question

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/answers/question.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tag_ids=(value) ⇒ Object (writeonly)

Sets the attribute tag_ids

Parameters:

  • value

    the value to set the attribute tag_ids to.



8
9
10
# File 'app/models/answers/question.rb', line 8

def tag_ids=(value)
  @tag_ids = value
end

Class Method Details

.tagsObject

returns tags in order of most taggings to least taggings



15
16
17
# File 'app/models/answers/question.rb', line 15

def self.tags
  self.tag_counts_on(:tags).sort_by(&:taggings_count).reverse
end

.tags_with_questionsObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/answers/question.rb', line 19

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

Instance Method Details

#top_answerObject



10
11
12
# File 'app/models/answers/question.rb', line 10

def top_answer
  self.answers.first
end