Browse files

* remove previous answers if new answer is stored

 * change results display to show all results on pick any questions
  • Loading branch information...
1 parent c890e24 commit 027bac9abc2fe0448882678581dfed6de71f84fc Mathias Kutzner committed with gorenje Jun 3, 2011
View
4 app/controllers/results_controller.rb
@@ -1,6 +1,6 @@
class ResultsController < ApplicationController
helper 'surveyor'
- layout 'results'
+ layout 'results'
def index
@surveys = Survey.all
end
@@ -10,4 +10,4 @@ def show
@response_sets = @survey.response_sets
@questions = @survey.sections_with_questions.map(&:questions).flatten
end
-end
+end
View
2 app/helpers/results_helper.rb
@@ -9,7 +9,7 @@ def display_response(r_set, question)
elsif sets.size == 1
(sets.first.string_value || sets.first.text_value || show_answer(sets.first))
else
- show_answer( sets.sort_by {|a| a.id }.last )
+ sets.map{|s| show_answer(s) }.join(", ")
end
end
View
2 lib/surveyor/surveyor_controller_methods.rb
@@ -67,12 +67,14 @@ def update
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 })
@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

0 comments on commit 027bac9

Please sign in to comment.