From 1be3ce0c60006e321d01960bf1a69ebb893e6b40 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 29 Sep 2021 15:59:41 +0100 Subject: [PATCH] DRY up partials --- app/controllers/case_logs_controller.rb | 13 ++++++++----- app/views/form/_checkbox_question.html.erb | 2 +- app/views/form/_date_question.html.erb | 2 -- app/views/form/_numeric_question.html.erb | 2 -- app/views/form/_radio_question.html.erb | 3 --- app/views/form/_text_question.html.erb | 2 -- app/views/form/page.html.erb | 6 +++++- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index dddcaee35..56919deda 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -1,4 +1,5 @@ class CaseLogsController < ApplicationController + def index @submitted_case_logs = CaseLog.where(status: 1) @in_progress_case_logs = CaseLog.where(status: 0) @@ -17,7 +18,7 @@ class CaseLogsController < ApplicationController def edit @form = Form.new(2021, 2022) @case_log = CaseLog.find(params[:id]) - render :edit, locals: { form: @form } + render :edit end def next_page @@ -31,10 +32,6 @@ class CaseLogsController < ApplicationController redirect_to(send("case_log_#{next_page}_path", @case_log)) end - def page_params(questions_for_page) - params.permit(questions_for_page) - end - form = Form.new(2021, 2022) form.all_pages.map do |page_key, page_info| define_method(page_key) do @@ -42,4 +39,10 @@ class CaseLogsController < ApplicationController render "form/page", locals: { case_log_id: @case_log.id, form: form, page_key: page_key, page_info: page_info } end end + + private + + def page_params(questions_for_page) + params.permit(questions_for_page) + end end diff --git a/app/views/form/_checkbox_question.html.erb b/app/views/form/_checkbox_question.html.erb index 144adad56..e41ab5029 100644 --- a/app/views/form/_checkbox_question.html.erb +++ b/app/views/form/_checkbox_question.html.erb @@ -12,4 +12,4 @@ <% end %> <%= f.hidden_field :previous_page, value: page_key %> -<%= f.hidden_field :case_log_id, value: case_log_id %> +<%= f.hidden_field :case_log_id, value: case_log.id %> diff --git a/app/views/form/_date_question.html.erb b/app/views/form/_date_question.html.erb index 245565eca..413f0255e 100644 --- a/app/views/form/_date_question.html.erb +++ b/app/views/form/_date_question.html.erb @@ -3,5 +3,3 @@ legend: { text: question["header"], size: "l"}, width: 20 %> -<%= f.hidden_field :previous_page, value: page_key %> -<%= f.hidden_field :case_log_id, value: case_log_id %> diff --git a/app/views/form/_numeric_question.html.erb b/app/views/form/_numeric_question.html.erb index 709ff3dbe..3df0fbe86 100644 --- a/app/views/form/_numeric_question.html.erb +++ b/app/views/form/_numeric_question.html.erb @@ -3,5 +3,3 @@ label: { text: question["header"], size: "l"}, min: question["min"], max: question["max"], step: question["step"], width: 20 %> -<%= f.hidden_field :previous_page, value: page_key %> -<%= f.hidden_field :case_log_id, value: case_log_id %> diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb index 0a6b38417..3681bb21d 100644 --- a/app/views/form/_radio_question.html.erb +++ b/app/views/form/_radio_question.html.erb @@ -11,6 +11,3 @@ <% end %> <% end %> <% end %> - -<%= f.hidden_field :previous_page, value: page_key %> -<%= f.hidden_field :case_log_id, value: case_log_id %> diff --git a/app/views/form/_text_question.html.erb b/app/views/form/_text_question.html.erb index 2000ca962..c040be8d9 100644 --- a/app/views/form/_text_question.html.erb +++ b/app/views/form/_text_question.html.erb @@ -3,5 +3,3 @@ label: { text: question["header"], size: "l"}, width: 20 %> -<%= f.hidden_field :previous_page, value: page_key %> -<%= f.hidden_field :case_log_id, value: case_log_id %> diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index 9a43208d9..997587d37 100644 --- a/app/views/form/page.html.erb +++ b/app/views/form/page.html.erb @@ -12,9 +12,13 @@ <% end %> <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> + <% page_info["questions"].map do |question_key, question| %> - <%= render partial: "form/#{question["type"]}_question", locals: { case_log_id: case_log_id, page_key: page_key, question_key: question_key, question: question, f: f } %> + <%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key, question: question, f: f } %> <% end %> + + <%= f.hidden_field :previous_page, value: page_key %> + <%= f.hidden_field :case_log_id, value: case_log_id %> <%= f.govuk_submit "Save and continue" %> <% end %> <% end %>