diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index b34ab0740..f162f1f64 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -28,13 +28,13 @@ class CaseLogsController < ApplicationController answers_for_page = page_params(questions_for_page).select { |k, _v| questions_for_page.include?(k) } @case_log.update!(answers_for_page) next_page = form.next_page(previous_page) - redirect_path = if next_page == :check_answers + redirect_path = if next_page == :check_answers subsection = form.subsection_for_page(previous_page) "case_log_#{subsection}_check_answers_path" - else + else "case_log_#{next_page}_path" end - + redirect_to(send(redirect_path, @case_log)) end @@ -44,7 +44,7 @@ class CaseLogsController < ApplicationController current_url = request.env['PATH_INFO'] subsection = current_url.split('/')[-2] subsection_pages = form.pages_for_subsection(subsection) - render "form/check_answers", locals: { case_log_id: @case_log.id, case_log: @case_log, subsection_pages: subsection_pages } + render "form/check_answers", locals: { case_log: @case_log, subsection_pages: subsection_pages } end form = Form.new(2021, 2022) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 883105de9..464f42fab 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -13,8 +13,8 @@ module CheckAnswersHelper link_to(link_name, "/case_logs/#{case_log_id}/#{page}", class: "govuk-link").html_safe end - def create_next_missing_question_link(case_log_id, subsections, case_log) - empty_question = subsections.keys.find{|x| case_log[x].blank? } + def create_next_missing_question_link(case_log_id, subsection_pages, case_log) + empty_question = subsection_pages.keys.find{|x| case_log[x].blank? } url = "/case_logs/#{case_log_id}/#{empty_question}" link_to('Answer the missing questions', url, class: "govuk-link").html_safe diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb new file mode 100644 index 000000000..b4551f622 --- /dev/null +++ b/app/views/form/_check_answers_table.html.erb @@ -0,0 +1,13 @@ +
+
+
+ <%= page_info["check_answer_label"].to_s %> +
+
+ <%= case_log[page] %> +
+
+ <%= create_update_answer_link(case_log[page], case_log["id"], page)%> +
+
+
diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index 8df10dcc8..872f7ae92 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -1,24 +1,11 @@ <%= turbo_frame_tag "case_log_form", target: "_top" do %>

Check the answers you gave for household characteristics

You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= subsection_pages.count %> questions

- <%= create_next_missing_question_link(case_log_id, subsection_pages, case_log) %> + <%= create_next_missing_question_link(case_log["id"], subsection_pages, case_log) %> <% subsection_pages.each do |page, page_info| %> -
-
-
- <%= page_info["check_answer_label"].to_s %> -
-
- <%= case_log[page] %> -
-
- <%= create_update_answer_link(case_log[page], case_log_id, page)%> -
-
-
+ <%= render partial: 'form/check_answers_table', locals: { page: page, page_info: page_info, case_log: case_log } %> <% end %> <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> <%= f.govuk_submit "Save and continue" %> <% end %> <% end %> - diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 9f0e5e643..2af4c5433 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -59,7 +59,7 @@ RSpec.describe "Test Features" do when "text" fill_in(question.to_s, with: answer) when "radio" - choose("#{question.to_s.tr('_', '-')}-#{answer.parameterize}-field") + choose("#{question.to_s.dasherize}-#{answer.parameterize}-field") else fill_in(question.to_s, with: answer) end