Sha256: 60d14856b74fa35289c717c6fbadd10bfcf80774d64970e41cb6d5da6f42e83c

Contents?: true

Size: 897 Bytes

Versions: 1

Compression:

Stored size: 897 Bytes

Contents

module Rostra
  class Question < ActiveRecord::Base

    belongs_to :user
    has_many :answers

    acts_as_taggable
    acts_as_voteable
    is_impressionable

    validates :title, :presence => true, :uniqueness => true, :length => { :minimum => 15 }
    validates :user, :presence => true
    validates :tag_list, :presence => true

    # Finds questions asked within the last 15 days ordered by non-unique page views.
    #
    def self.trending(limit = 5)
      return [] if Question.count.zero?
      Question
        .where(created_at: (15.days.ago)..(Time.now))
        .limit(limit)
        .joins(:impressions)
        .group('impressions.impressionable_id')
        .order('count(impressions.impressionable_id) desc')
    end

    def answer_count
      @answer_count = answers.count
    end

    def unique_page_views
      impressionist_count(filter: :ip_address)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rostra-0.0.5 app/models/rostra/question.rb