From 0490f6b78d0d29f5d51da9c96fd387d7c2a86496 Mon Sep 17 00:00:00 2001 From: Luke Baker Date: Mon, 10 Sep 2012 11:57:27 -0400 Subject: [PATCH] lock question before updating choice --- app/controllers/choices_controller.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/choices_controller.rb b/app/controllers/choices_controller.rb index 2d9ab78..8a9b9eb 100644 --- a/app/controllers/choices_controller.rb +++ b/app/controllers/choices_controller.rb @@ -88,9 +88,12 @@ class ChoicesController < InheritedResources::Base # prevent AttributeNotFound error and only update actual Choice columns, since we add extra information in 'show' method choice_attributes = Choice.new.attribute_names params[:choice] = params[:choice].delete_if {|key, value| !choice_attributes.include?(key)} - @question = current_user.questions.find(params[:question_id]) - @choice = @question.choices.find(params[:id]) - update! + Choice.transaction do + # lock question since we'll need a lock on it later in Choice.update_questions_counter + @question = current_user.questions.find(params[:question_id], :lock => true) + @choice = @question.choices.find(params[:id]) + update! + end end def show -- libgit2 0.21.2