Files
nairobi/app/controllers/polls/questions_controller.rb
Senén Rodero Rodríguez 527d5691f7 Make poll feature work in browsers with javascript disabled
By using the Rails `button_to` helper (which generates a form), and adapting the
response to `html` and `js` formats, the feature works with or without javascript
enabled.
2022-09-22 17:39:57 +02:00

25 lines
619 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)
answer.answer = params[:answer]
answer.save_and_record_voter_participation
@answers_by_question_id = { @question.id => params[:answer] }
respond_to do |format|
format.html do
redirect_to request.referer
end
format.js do
render :answer
end
end
end
end