Browse Source

Save all answers on page

pull/23/head
baarkerlounger 3 years ago committed by Daniel Baark
parent
commit
f17d480a12
  1. 9
      app/controllers/case_logs_controller.rb
  2. 5
      app/models/form.rb
  3. 30
      config/forms/2021_2022.json

9
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

5
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

30
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"

Loading…
Cancel
Save