displays only proposals from last week ordered by votes

This commit is contained in:
rgarcia
2016-02-16 12:22:20 +01:00
parent 6540092bcd
commit 0432151e6b
2 changed files with 2 additions and 2 deletions

View File

@@ -36,7 +36,7 @@ class ProposalsController < ApplicationController
end end
def summary def summary
@proposals = Proposal.grouped_by_categories(Proposal.category_names) @proposals = Proposal.last_week.sort_by_confidence_score.grouped_by_categories(Proposal.category_names)
end end
private private

View File

@@ -41,7 +41,7 @@ class Proposal < ActiveRecord::Base
scope :sort_by_random, -> { reorder("RANDOM()") } scope :sort_by_random, -> { reorder("RANDOM()") }
scope :sort_by_relevance , -> { all } scope :sort_by_relevance , -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :last_week, -> { where("created_at >= ?", 7.days.ago)} scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
scope :grouped_by_categories, -> (categories) { where("lower(tags.name) IN (?)", categories). scope :grouped_by_categories, -> (categories) { where("lower(tags.name) IN (?)", categories).
joins(:tags).select('proposals.*, tags.name'). joins(:tags).select('proposals.*, tags.name').