Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* bugfix for :pick => :any questions

   * 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...
commit 1acfd7556a7bb5ea1f99a5ed0e104b029b933496 1 parent 0244408
Mathias Kutzner authored
Showing with 10 additions and 11 deletions.
  1. +10 −11 lib/surveyor/surveyor_controller_methods.rb
View
21 lib/surveyor/surveyor_controller_methods.rb
@@ -63,20 +63,20 @@ def update
:lock => true)
return redirect_with_message(available_surveys_path, :notice,
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])
saved = false
- if params[:finish]
- ActiveRecord::Base.transaction do
- @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 })
+
+ ActiveRecord::Base.transaction do
+ # ensure that all answers for the submitted questions are removed even if there are no new answers
+ @response_set.responses.where("question_id" => question_ids).each{ |r| r.destroy }
+ saved = @response_set.update_attributes( { :responses_attributes => parameters_sanitized })
+
+ if params[:finish]
@response_set.complete! if saved
saved &= @response_set.save
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
return redirect_with_message(surveyor_finish, :notice,
@@ -90,13 +90,12 @@ def update
end
format.js do
- ids, remove, question_ids = {}, {}, []
+ ids, remove = {}, {}
parameters_sanitized.each do |k,v|
ids[k] = @response_set.responses.
find(:first, :conditions => v).id unless v.has_key?("id")
remove[k] = v["id"] if v.has_key?("id") && v.has_key?("_destroy")
- question_ids << v["question_id"]
end
render :json => {"ids" => ids, "remove" => remove}.

5 comments on commit 1acfd75

@kobaltz

One Issue that I'm experiencing with this commit is if I already have items checked off and I go back to the survey and add an additional item, all of the previous items are removed. Only the new items are saved. Also, whenever I check off a few items that I'm changing, I get an error (404) when going to the next tab. It looks like this could be a mapping issue on my end.

@kobaltz

What it looks like it's doing on your line 73 is deleting everything. But existing items that were not unchecked are also being deleted. Any idea how to keep those?

@gorenje
Owner

hm, but the question ids that are deleted are the ones that came over the wire. That shoud really mean that we have new answers for these questions. ok, but i'm not 100% sure, we'll investigate and try to find a fix for this ...

@ewto

should be fixed by ewto@1947036

@kobaltz

Excellent. The pick any is finally working the way it should be. Thanks so much!

Please sign in to comment.
Something went wrong with that request. Please try again.