diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index a7c0fa286..b25c2838e 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -41,14 +41,15 @@ class SchemesController < ApplicationController end def update + check_answers = params[:scheme][:check_answers] + page = params[:scheme][:page] + if @scheme.update(scheme_params) - if params[:scheme][:check_answers] == "true" - if params[:scheme][:page] == "confirm-secondary" && @scheme.has_other_client_group == "Yes" + if check_answers + if confirm_secondary_page? page redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true") else - if @scheme.has_other_client_group == "No" - @scheme.update!(secondary_client_group: nil) - end + @scheme.update!(secondary_client_group: nil) unless @scheme.has_other_client_group == "Yes" redirect_to scheme_check_answers_path(@scheme) end else @@ -87,6 +88,10 @@ class SchemesController < ApplicationController private + def confirm_secondary_page? page + page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" + end + def next_page_path(page) case page when "primary-client-group" @@ -103,7 +108,20 @@ private end def scheme_params - required_params = params.require(:scheme).permit(:service_name, :sensitive, :organisation_id, :stock_owning_organisation_id, :scheme_type, :registered_under_care_act, :total_units, :id, :has_other_client_group, :primary_client_group, :secondary_client_group, :support_type, :intended_stay) + required_params = params.require(:scheme).permit(:service_name, + :sensitive, + :organisation_id, + :stock_owning_organisation_id, + :scheme_type, + :registered_under_care_act, + :total_units, + :id, + :has_other_client_group, + :primary_client_group, + :secondary_client_group, + :support_type, + :intended_stay) + required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] if current_user.data_coordinator? required_params[:organisation_id] = current_user.organisation_id diff --git a/app/views/schemes/details.html.erb b/app/views/schemes/details.html.erb index 1b7007d3a..73ef511aa 100644 --- a/app/views/schemes/details.html.erb +++ b/app/views/schemes/details.html.erb @@ -67,7 +67,7 @@ legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> <%= f.hidden_field :page, value: "details" %> - <% if request.query_parameters["check_answers"] == "true" %> + <% if request.query_parameters["check_answers"] %> <%= f.hidden_field :check_answers, value: "true" %> <% end %> <%= f.govuk_submit "Save and continue" %>