Change Debate.sort_by method for individual scopes

This commit is contained in:
Marko Lovic
2015-08-27 12:42:05 +02:00
parent 6f32801a88
commit b6df3be8c0
2 changed files with 5 additions and 12 deletions

View File

@@ -28,6 +28,10 @@ class Debate < ActiveRecord::Base
scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") }
scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") }
scope :for_render, -> { includes(:tags) }
scope :sort_by_total_votes, -> { reorder(cached_votes_total: :desc) }
scope :sort_by_likes , -> { reorder(cached_votes_up: :desc) }
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
# Ahoy setup
visitable # Ahoy will automatically assign visit_id on create
@@ -40,17 +44,6 @@ class Debate < ActiveRecord::Base
end
end
def self.sort_by(order)
case order
when 'total_votes'
reorder(cached_votes_total: :desc)
when 'created_at'
reorder(created_at: :desc)
when 'likes'
reorder(cached_votes_up: :desc)
end
end
def likes
cached_votes_up
end