@@ -22,7 +22,7 @@ class QuestionForm < Rapidfire::BaseService
2222
2323 attr_accessor :survey , :question , :default_text , :placeholder ,
2424 :type , :question_text , :position , :answer_options , :answer_presence ,
25- :answer_minimum_length , :answer_maximum_length ,
25+ :answer_minimum_length , :answer_maximum_length , :files ,
2626 :answer_greater_than_or_equal_to , :answer_less_than_or_equal_to
2727
2828 delegate :valid? , :errors , :to => :question
@@ -47,11 +47,15 @@ def create_question
4747 return false
4848 end
4949
50- @question = klass . create ( to_question_params )
50+ @question = klass . create ( to_question_params ) . tap do |new_question |
51+ attach_files ( new_question )
52+ end
5153 end
5254
5355 def update_question
54- @question . update ( to_question_params )
56+ result = @question . update ( to_question_params )
57+ attach_files ( @question ) if result
58+ result
5559 end
5660
5761 def to_question_params
@@ -73,11 +77,18 @@ def to_question_params
7377 }
7478 end
7579
80+ def attach_files ( question )
81+ if files . present?
82+ files . each { |f | question . files . attach ( f ) }
83+ end
84+ end
85+
7686 def from_question_to_attributes ( question )
7787 self . type = question . type
7888 self . survey = question . survey
7989 self . question_text = question . question_text
8090 self . position = question . position
91+ self . files = question . files if question . files . attached?
8192 self . default_text = question . default_text
8293 self . placeholder = question . placeholder
8394 self . answer_options = question . answer_options
0 commit comments