Commit 0490f6b78d0d29f5d51da9c96fd387d7c2a86496
1 parent
f408721c
Exists in
master
and in
1 other branch
lock question before updating choice
Showing
1 changed file
with
6 additions
and
3 deletions
Show diff stats
app/controllers/choices_controller.rb
... | ... | @@ -88,9 +88,12 @@ class ChoicesController < InheritedResources::Base |
88 | 88 | # prevent AttributeNotFound error and only update actual Choice columns, since we add extra information in 'show' method |
89 | 89 | choice_attributes = Choice.new.attribute_names |
90 | 90 | params[:choice] = params[:choice].delete_if {|key, value| !choice_attributes.include?(key)} |
91 | - @question = current_user.questions.find(params[:question_id]) | |
92 | - @choice = @question.choices.find(params[:id]) | |
93 | - update! | |
91 | + Choice.transaction do | |
92 | + # lock question since we'll need a lock on it later in Choice.update_questions_counter | |
93 | + @question = current_user.questions.find(params[:question_id], :lock => true) | |
94 | + @choice = @question.choices.find(params[:id]) | |
95 | + update! | |
96 | + end | |
94 | 97 | end |
95 | 98 | |
96 | 99 | def show | ... | ... |