I'm not sure why the code didn't work without this line, but it doesn't seem to be necessary anymore (maybe after upgrading Ruby or Rails?). I'm removing it now because... why not now? :) The Ruby interpreter is raising a warning due to this line, and in Ruby 2.5 constant lookup has changed slightly (although I don't think this line is affected by that change). Note about the change in the Setting model: Ruby actually ignores return values in setter methods, so the line isn't necessary.
51 lines
1.3 KiB
Ruby
51 lines
1.3 KiB
Ruby
class PollsController < ApplicationController
|
|
include PollsHelper
|
|
|
|
before_action :load_poll, except: [:index]
|
|
before_action :load_active_poll, only: :index
|
|
|
|
load_and_authorize_resource
|
|
|
|
has_filters %w[current expired]
|
|
has_orders %w[most_voted newest oldest], only: :show
|
|
|
|
def index
|
|
@polls = Kaminari.paginate_array(
|
|
@polls.created_by_admin.not_budget.send(@current_filter).includes(:geozones).sort_for_list
|
|
).page(params[:page])
|
|
end
|
|
|
|
def show
|
|
@questions = @poll.questions.for_render.sort_for_list
|
|
@token = poll_voter_token(@poll, current_user)
|
|
@poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
|
|
.where.not(description: "").order(:given_order)
|
|
|
|
@answers_by_question_id = {}
|
|
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user&.id)
|
|
poll_answers.each do |answer|
|
|
@answers_by_question_id[answer.question_id] = answer.answer
|
|
end
|
|
|
|
@commentable = @poll
|
|
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
|
end
|
|
|
|
def stats
|
|
@stats = Poll::Stats.new(@poll)
|
|
end
|
|
|
|
def results
|
|
end
|
|
|
|
private
|
|
|
|
def load_poll
|
|
@poll = Poll.find_by_slug_or_id!(params[:id])
|
|
end
|
|
|
|
def load_active_poll
|
|
@active_poll = ActivePoll.first
|
|
end
|
|
end
|