diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 3f39330c1..e4eb6f44d 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -24,12 +24,17 @@ class CaseLogsController < ApplicationController form = Form.new(2021, 2022) @case_log = CaseLog.find(params[:case_log_id]) previous_page = params[:previous_page] - previous_answer = params[previous_page] - @case_log.update!(previous_page => previous_answer) + questions_for_page = form.questions_for_page(previous_page).keys + 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_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.keys.map do |page| define_method(page) do diff --git a/app/models/form.rb b/app/models/form.rb index 6dcd32e77..5684fae92 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -32,6 +32,11 @@ class Form all_subsections[subsection]["pages"] end + # Returns a hash with the questions as keys + def questions_for_page(page) + all_pages[page]["questions"] + end + def first_page_for_subsection(subsection) pages_for_subsection(subsection).keys.first end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 55fec6946..47948d6b6 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -169,12 +169,12 @@ "household_needs": { "label": "Household needs", "pages": { - "tenant_code":{ + "previous_housing_situation":{ "header": "", "description": "", "questions":{ - "tenant_code": { - "header": "What is the tenant code?", + "previous_housing_situation": { + "header": "What was the tenant’s housing situation immediately before this letting?", "hint_text": "", "type": "text" } @@ -190,11 +190,11 @@ "tenancy_information": { "label": "Tenancy information", "pages": { - "tenant_code":{ + "tenant_code_1":{ "header": "", "description": "", "questions":{ - "tenant_code": { + "tenant_code_1": { "header": "What is the tenant code?", "hint_text": "", "type": "text" @@ -206,11 +206,11 @@ "property_information": { "label": "Property information", "pages": { - "tenant_code":{ + "tenant_code_2":{ "header": "", "description": "", "questions":{ - "tenant_code": { + "tenant_code_2": { "header": "What is the tenant code?", "hint_text": "", "type": "text" @@ -227,11 +227,11 @@ "income_and_benefits": { "label": "Income and benefits", "pages": { - "tenant_code":{ + "tenant_code_3":{ "header": "", "description": "", "questions":{ - "tenant_code": { + "tenant_code_3": { "header": "What is the tenant code?", "hint_text": "", "type": "text" @@ -243,11 +243,11 @@ "rent": { "label": "Rent", "pages": { - "tenant_code":{ + "tenant_code_4":{ "header": "", "description": "", "questions":{ - "tenant_code": { + "tenant_code_4": { "header": "What is the tenant code?", "hint_text": "", "type": "text" @@ -264,11 +264,11 @@ "local_authority": { "label": "Local authority", "pages": { - "tenant_code":{ + "tenant_code_5":{ "header": "", "description": "", "questions":{ - "tenant_code": { + "tenant_code_5": { "header": "What is the tenant code?", "hint_text": "", "type": "text" @@ -285,11 +285,11 @@ "declaration": { "label": "Declaration", "pages": { - "tenant_code":{ + "tenant_code_6":{ "header": "", "description": "", "questions":{ - "tenant_code": { + "tenant_code_6": { "header": "What is the tenant code?", "hint_text": "", "type": "text"