diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 2cb65edaf..7d6b60822 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -38,7 +38,7 @@ class FormController < ApplicationController end error_attributes = @log.errors.map(&:attribute) Rails.logger.info "User triggered validation(s) on: #{error_attributes.join(', ')}" - @subsection = form.subsection_for_page(@page) + @subsection = @page.subsection flash[:errors] = @log.errors.each_with_object({}) do |error, result| if @page.questions.map(&:id).include?(error.attribute.to_s) result[error.attribute.to_s] = error.message @@ -87,7 +87,7 @@ class FormController < ApplicationController if @log page_id = request.path.split("/")[-1].underscore @page = form.get_page(page_id) - @subsection = form.subsection_for_page(@page) + @subsection = @page.subsection @pages_with_errors_count = 0 if @page.routed_to?(@log, current_user) || is_referrer_type?("interruption_screen") || adding_answer_from_check_errors_page? if updated_answer_from_check_errors_page? @@ -274,7 +274,7 @@ private elsif pages_to_check.any? return redirect_path_to_question(pages_to_check[0], pages_to_check) else - return send("#{@log.log_type}_#{form.subsection_for_page(@page).id}_check_answers_path", @log) + return send("#{@log.log_type}_#{@page.subsection.id}_check_answers_path", @log) end end if previous_interruption_screen_page_id.present? diff --git a/app/models/form.rb b/app/models/form.rb index a6558efab..0205bba84 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -78,14 +78,10 @@ class Form routed_question || all_questions[0] end - def subsection_for_page(page) - subsections.find { |s| s.pages.find { |p| p.id == page.id } } - end - def next_page_id(page, log, current_user, ignore_answered: false) return page.next_unresolved_page_id || :check_answers if log.unresolved - page_ids = subsection_for_page(page).pages.map(&:id) + page_ids = page.subsection.pages.map(&:id) page_index = page_ids.index(page.id) page_id = if page.interruption_screen? && log[page.questions[0].id] == 1 && page.routed_to?(log, current_user) previous_page_id(page, log, current_user) @@ -104,14 +100,14 @@ class Form def next_page_redirect_path(page, log, current_user, ignore_answered: false) next_page_id = next_page_id(page, log, current_user, ignore_answered:) if next_page_id == :check_answers - "#{type}_log_#{subsection_for_page(page).id}_check_answers_path" + "#{type}_log_#{page.subsection.id}_check_answers_path" else "#{type}_log_#{next_page_id}_path" end end def previous_page_id(page, log, current_user) - page_ids = subsection_for_page(page).pages.map(&:id) + page_ids = page.subsection.pages.map(&:id) page_index = page_ids.index(page.id) return :tasklist if page_index.zero? @@ -126,7 +122,7 @@ class Form def previous_page_redirect_path(page, log, current_user, referrer) previous_page_id = previous_page_id(page, log, current_user) if referrer == "check_answers" - "#{type}_log_#{subsection_for_page(page).id}_check_answers_path" + "#{type}_log_#{page.subsection.id}_check_answers_path" elsif previous_page_id == :tasklist "#{type}_log_path" else diff --git a/app/services/documentation_generator.rb b/app/services/documentation_generator.rb index 4e0a7011c..999216d6d 100644 --- a/app/services/documentation_generator.rb +++ b/app/services/documentation_generator.rb @@ -301,7 +301,7 @@ Look at these helper methods where needed to understand what is being checked in end def save_soft_validation(form, page, validation_descriptions, log_type) - subsection_pages = form.subsection_for_page(page).pages + subsection_pages = page.subsection.pages page_index = subsection_pages.index(page) page_the_validation_applied_to = subsection_pages[page_index - 1]