Add recommended tab on proposals and debates index.

This commit is contained in:
taitus
2017-07-28 13:43:01 +02:00
parent 01a41b4706
commit fe3bb7a389
15 changed files with 92 additions and 43 deletions

View File

@@ -37,14 +37,27 @@ class Debate < ActiveRecord::Base
scope :sort_by_random, -> { reorder("RANDOM()") }
scope :sort_by_relevance, -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_recommended, -> { order(cached_votes_total: :desc) }
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
scope :featured, -> { where("featured_at is not null")}
scope :public_for_api, -> { all }
# Ahoy setup
visitable # Ahoy will automatically assign visit_id on create
attr_accessor :link_required
def self.recommended(user)
debates_list = where("author_id != ?", user.id)
#same as "with_tagged(user.interests, any: true)"
debates_list_with_tagged = debates_list.joins(:tags).where('taggings.taggable_type = ?', self.name).where('tags.name IN (?)', user.interests)
if debates_list_with_tagged.any?
debates_list = debates_list_with_tagged
end
debates_list
end
def searchable_values
{ title => 'A',
author.username => 'B',
@@ -135,4 +148,9 @@ class Debate < ActiveRecord::Base
featured_at.present?
end
def self.debates_orders(user)
orders = %w{hot_score confidence_score created_at relevance}
orders << "recommended" if user.present?
orders
end
end