File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed
Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -85,14 +85,7 @@ def create_or_update
8585 # check should probably happen on create/update
8686 return unless @answer . present?
8787
88- @plan = Plan . includes (
89- sections : {
90- questions : %i[
91- answers
92- question_format
93- ]
94- }
95- ) . find ( p_params [ :plan_id ] )
88+ @plan = fetch_plan_with_associations ( p_params [ :plan_id ] )
9689 @question = @answer . question
9790 @section = @plan . sections . find_by ( id : @question . section_id )
9891 template = @section . phase . template
@@ -108,14 +101,7 @@ def create_or_update
108101 end
109102 end
110103 # Now update @plan after removing answers of questions removed from the plan.
111- @plan = Plan . includes (
112- sections : {
113- questions : %i[
114- answers
115- question_format
116- ]
117- }
118- ) . find ( p_params [ :plan_id ] )
104+ @plan = fetch_plan_with_associations ( p_params [ :plan_id ] )
119105
120106 # Now get list of question ids to remove based on remaining answers.
121107 remove_list_question_ids = remove_list ( @plan )
@@ -196,6 +182,17 @@ def permitted_params
196182 end
197183 # rubocop:enable Metrics/AbcSize
198184
185+ def fetch_plan_with_associations ( plan_id )
186+ Plan . includes (
187+ sections : {
188+ questions : %i[
189+ answers
190+ question_format
191+ ]
192+ }
193+ ) . find ( plan_id )
194+ end
195+
199196 def check_answered ( section , q_array , all_answers )
200197 n_qs = section . questions . count { |question | q_array . include? ( question . id ) }
201198 n_ans = all_answers . count { |ans | q_array . include? ( ans . question . id ) and ans . answered? }
You can’t perform that action at this time.
0 commit comments