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) 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