Adds featured debates

This commit is contained in:
Alberto Garcia Cabeza
2015-11-13 11:39:49 +01:00
parent 68b4d36af2
commit 859dfc09e0
7 changed files with 146 additions and 23 deletions

View File

@@ -12,11 +12,24 @@ class DebatesController < ApplicationController
load_and_authorize_resource
respond_to :html, :js
def index_customization
@featured_debates = Debate.all.sort_by_confidence_score.limit(3) if (@search_terms.blank? && @tag_filter.blank?)
if @featured_debates.present?
set_featured_debate_votes(@featured_debates)
@resources = @resources.where('debates.id NOT IN (?)', @featured_debates.map(&:id))
end
end
def vote
@debate.register_vote(current_user, params[:value])
set_debate_votes(@debate)
end
def vote_featured
@debate.register_vote(current_user, 'yes')
set_featured_debate_votes(@debate)
end
private
def debate_params
@@ -27,4 +40,7 @@ class DebatesController < ApplicationController
Debate
end
def set_featured_debate_votes(debates)
@featured_debates_votes = current_user ? current_user.debate_votes(debates) : {}
end
end