Files
grecia/app/controllers/polls_controller.rb

29 lines
786 B
Ruby

class PollsController < ApplicationController
include CommentableActions
load_and_authorize_resource
has_filters %w{current expired incoming}
has_orders %w{most_voted newest oldest}, only: :show
::Poll::Answer # trigger autoload
def index
@polls = @polls.send(@current_filter).includes(:geozones).sort_for_list.page(params[:page])
end
def show
@questions = @poll.questions.for_render.sort_for_list
@commentable = @poll
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
@answers_by_question_id = {}
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
poll_answers.each do |answer|
@answers_by_question_id[answer.question_id] = answer.answer
end
end
end