Skip to content

Commit

Permalink
* bugfix for :pick => :any questions
Browse files Browse the repository at this point in the history
   * if the last checkbox was deselected, the corresponding responses weren't removed
   * conditions (dependencies) depending on the corresponding question weren't fulfilled
  • Loading branch information
Mathias Kutzner committed Jun 10, 2011
1 parent 0244408 commit 1acfd75
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/surveyor/surveyor_controller_methods.rb
Expand Up @@ -63,20 +63,20 @@ def update
:lock => true) :lock => true)
return redirect_with_message(available_surveys_path, :notice, return redirect_with_message(available_surveys_path, :notice,
t('surveyor.unable_to_find_your_responses')) if @response_set.blank? t('surveyor.unable_to_find_your_responses')) if @response_set.blank?

question_ids = params[:r].values.map{|r| r["question_id"]}.flatten.uniq
parameters_sanitized = ResponseSet.reject_or_destroy_blanks(params[:r]) parameters_sanitized = ResponseSet.reject_or_destroy_blanks(params[:r])
saved = false saved = false
if params[:finish]
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@response_set.responses.where("question_id" => parameters_sanitized.values.map{|r| r["question_id"]}.flatten.uniq).each{ |r| r.destroy } # ensure that all answers for the submitted questions are removed even if there are no new answers
saved = @response_set. @response_set.responses.where("question_id" => question_ids).each{ |r| r.destroy }
update_attributes( { :responses_attributes => parameters_sanitized }) saved = @response_set.update_attributes( { :responses_attributes => parameters_sanitized })

if params[:finish]
@response_set.complete! if saved @response_set.complete! if saved
saved &= @response_set.save saved &= @response_set.save
end end
else
@response_set.responses.where("question_id" => parameters_sanitized.values.map{|r| r["question_id"]}.flatten.uniq).each{ |r| r.destroy }
saved = @response_set.
update_attributes( { :responses_attributes => parameters_sanitized })
end end


return redirect_with_message(surveyor_finish, :notice, return redirect_with_message(surveyor_finish, :notice,
Expand All @@ -90,13 +90,12 @@ def update
end end


format.js do format.js do
ids, remove, question_ids = {}, {}, [] ids, remove = {}, {}
parameters_sanitized.each do |k,v| parameters_sanitized.each do |k,v|
ids[k] = @response_set.responses. ids[k] = @response_set.responses.
find(:first, :conditions => v).id unless v.has_key?("id") find(:first, :conditions => v).id unless v.has_key?("id")


remove[k] = v["id"] if v.has_key?("id") && v.has_key?("_destroy") remove[k] = v["id"] if v.has_key?("id") && v.has_key?("_destroy")
question_ids << v["question_id"]
end end


render :json => {"ids" => ids, "remove" => remove}. render :json => {"ids" => ids, "remove" => remove}.
Expand Down

0 comments on commit 1acfd75

Please sign in to comment.