@@ -9,7 +9,7 @@ def create
99 @type_of_answer_input = Pages ::TypeOfAnswerInput . new ( answer_type_form_params )
1010
1111 if @type_of_answer_input . submit
12- redirect_to next_page_path ( current_form . id , @type_of_answer_input . answer_type , :create )
12+ redirect_to next_page_path ( @type_of_answer_input . answer_type )
1313 else
1414 @type_of_answer_path = type_of_answer_create_path ( current_form . id )
1515 render :type_of_answer , locals : { current_form : }
@@ -26,7 +26,7 @@ def update
2626 @type_of_answer_input = Pages ::TypeOfAnswerInput . new ( answer_type_form_params )
2727
2828 if @type_of_answer_input . submit
29- redirect_to next_page_path ( current_form . id , @type_of_answer_input . answer_type , :update )
29+ redirect_to next_page_path ( @type_of_answer_input . answer_type )
3030 else
3131 @type_of_answer_path = type_of_answer_update_path ( current_form . id )
3232 render :type_of_answer
@@ -35,54 +35,15 @@ def update
3535
3636private
3737
38- def selection_path ( form_id , action )
39- return question_text_new_path ( form_id ) if action == :create
40-
41- selection_type_edit_path ( form_id , page . id )
42- end
43-
44- def text_path ( form_id , action )
45- action == :create ? text_settings_new_path ( form_id ) : text_settings_edit_path ( form_id )
46- end
47-
48- def date_path ( form_id , action )
49- action == :create ? date_settings_new_path ( form_id ) : date_settings_edit_path ( form_id )
50- end
51-
52- def address_path ( form_id , action )
53- action == :create ? address_settings_new_path ( form_id ) : address_settings_edit_path ( form_id )
54- end
55-
56- def name_path ( form_id , action )
57- action == :create ? name_settings_new_path ( form_id ) : name_settings_edit_path ( form_id )
58- end
59-
60- def default_path ( form_id , action )
61- action == :create ? new_question_path ( form_id ) : edit_question_path ( form_id )
62- end
63-
64- def next_page_path ( form_id , answer_type , action )
65- case answer_type
66- when "selection"
67- selection_path ( form_id , action )
68- when "text"
69- text_path ( form_id , action )
70- when "date"
71- date_path ( form_id , action )
72- when "address"
73- address_path ( form_id , action )
74- when "name"
75- name_path ( form_id , action )
76- else
77- default_path ( form_id , action )
78- end
79- end
80-
8138 def answer_type_form_params
8239 params . require ( :pages_type_of_answer_input ) . permit ( :answer_type ) . merge ( draft_question :, current_form :)
8340 end
8441
8542 def answer_type_changed?
8643 @type_of_answer_input . answer_type != @type_of_answer_input . draft_question . answer_type
8744 end
45+
46+ def next_page_path ( answer_type )
47+ Pages ::AddOrEditQuestionService . new ( form_id : current_form . id , existing_page_id : page_id ) . new_or_edit_path_for_answer_type ( answer_type )
48+ end
8849end
0 commit comments