Up until now, we were assuming the voter was valid, but were not raising an exception if it wasn't. And in the user interface everything seemed to be working properly. We were having this issue when skipping verification, when there could be voters without a document number, which would be considered invalid. Raising an exception when failing to save the voter and making sure the answer and the voter are saved inside a transaction solves the problem.
17 lines
498 B
Ruby
17 lines
498 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.save_and_record_voter_participation(token)
|
|
|
|
@answers_by_question_id = { @question.id => params[:answer] }
|
|
end
|
|
end
|