adds featured proposals

via new action featured_vote
Featured proposals are never duplicated in the filtered lists
Featured are not calculated/shown in searches.
This commit is contained in:
Juanjo Bazán
2015-10-22 11:49:14 +02:00
committed by Juanjo Bazán
parent c896fc3eef
commit 1136c5546a
9 changed files with 125 additions and 59 deletions

View File

@@ -11,11 +11,24 @@ class ProposalsController < ApplicationController
load_and_authorize_resource
respond_to :html, :js
def index_customization
@featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if @search_terms.blank?
if @featured_proposals.present?
set_featured_proposal_votes(@featured_proposals)
@resources = @resources.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id))
end
end
def vote
@proposal.register_vote(current_user, 'yes')
set_proposal_votes(@proposal)
end
def vote_featured
@proposal.register_vote(current_user, 'yes')
set_featured_proposal_votes(@proposal)
end
private
def proposal_params
@@ -25,4 +38,8 @@ class ProposalsController < ApplicationController
def resource_model
Proposal
end
def set_featured_proposal_votes(proposals)
@featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {}
end
end