25 lines
695 B
Ruby
25 lines
695 B
Ruby
class Polls::QuestionsController < ApplicationController
|
|
|
|
load_and_authorize_resource :poll
|
|
load_and_authorize_resource :question, class: 'Poll::Question'
|
|
|
|
has_orders %w{most_voted newest oldest}, only: :show
|
|
|
|
def answer
|
|
answer = @question.answers.find_or_initialize_by(author: current_user)
|
|
token = params[:token]
|
|
|
|
answer.answer = params[:answer]
|
|
answer.touch if answer.persisted?
|
|
answer.save!
|
|
answer.record_voter_participation(token)
|
|
@question.question_answers
|
|
.where(question_id: @question, title: answer.answer)
|
|
.first
|
|
.set_most_voted
|
|
|
|
@answers_by_question_id = { @question.id => params[:answer] }
|
|
end
|
|
|
|
end
|