1- require 'csv'
1+ require "csv"
2+
23module Rapidfire
34 class Survey < ApplicationRecord
4- has_many :attempts
5- has_many :questions
6-
7- validates :name , :presence => true
5+ has_many :attempts , dependent : :destroy
6+ has_many :questions , dependent : :destroy
7+ has_many :answers , through : :attempts , dependent : :destroy
88
9-
10- if Rails ::VERSION ::MAJOR == 3
11- attr_accessible :name , :introduction , :after_survey_content
12- end
9+ validates :name , presence : true
1310
1411 def self . csv_user_attributes = ( attributes )
1512 @@csv_user_attributes = Array ( attributes )
@@ -24,24 +21,21 @@ def results_to_csv(filter)
2421 header = [ ]
2522 header += Rapidfire ::Survey . csv_user_attributes
2623 questions . each do |question |
27- header << ActionView ::Base . full_sanitizer . sanitize ( question . question_text , : tags => [ ] , : attributes => [ ] )
24+ header << ActionView ::Base . full_sanitizer . sanitize ( question . question_text , tags : [ ] , attributes : [ ] )
2825 end
2926 header << "results updated at"
3027 csv << header
31- attempts . where ( SurveyResults . filter ( filter , 'id' ) ) . each do |attempt |
28+ attempts . where ( SurveyResults . filter ( filter , "id" ) ) . each do |attempt |
3229 this_attempt = [ ]
3330
3431 Survey . csv_user_attributes . each do |attribute |
3532 this_attempt << attempt . user . try ( attribute )
3633 end
3734
3835 questions . each do |question |
39- answer = attempt . answers . detect { |a | a . question_id == question . id } . try ( :answer_text )
36+ answer = attempt . answers . detect { |a | a . question_id == question . id } . try ( :answer_text )
4037 this_attempt << answer
4138 end
42-
43- this_attempt << attempt . updated_at
44- csv << this_attempt
4539 end
4640 end
4741 end
0 commit comments