diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index e9ca47ea3..a54766bb2 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -20,31 +20,58 @@ class LocationsController < ApplicationController redirect_to scheme_location_postcode_path(@scheme, @location) end - def postcode; end + def postcode + if params[:location].present? + @location.postcode = params[:location][:postcode] + @location.save! + redirect_to scheme_location_name_path(@scheme, @location) + end + end def name - @location.update(location_params) + if params[:location].present? + @location.name = params[:location][:name] + @location.save! + redirect_to scheme_location_units_path(@scheme, @location) + end end def units - @location.update(location_params) + if params[:location].present? + @location.units = params[:location][:units] + @location.save! + redirect_to scheme_location_type_of_unit_path(@scheme, @location) + end end def type_of_unit - @location.update(location_params) + if params[:location].present? + @location.type_of_unit = params[:location][:type_of_unit] + @location.save! + redirect_to scheme_location_mobility_standards_path(@scheme, @location) + end end def mobility_standards - @location.update(location_params) + if params[:location].present? + @location.mobility_type = params[:location][:mobility_type] + @location.save! + redirect_to scheme_location_startdate_path(@scheme, @location) + end end def startdate - @location.update(location_params) + if params[:location].present? + day = params[:location]["startdate(3i)"] + month = params[:location]["startdate(2i)"] + year = params[:location]["startdate(1i)"] + @location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i) + @location.save! + redirect_to scheme_location_check_answers_path(@scheme, @location) + end end - def check_answers - @location.update(location_params) - end + def check_answers; end def show; end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 67a1a7a92..6d797e7fc 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -56,19 +56,19 @@ module LocationsHelper def location_edit_path(location, page) case page when "postcode" - scheme_location_postcode_path(location.scheme, location) + scheme_location_postcode_path(location.scheme, location, referrer: "check_answers") when "name" - scheme_location_name_path(location.scheme, location) + scheme_location_name_path(location.scheme, location, referrer: "check_answers") when "location_admin_district" - scheme_location_edit_local_authority_path(location.scheme, location) + scheme_location_edit_local_authority_path(location.scheme, location, referrer: "check_answers") when "units" - scheme_location_units_path(location.scheme, location) + scheme_location_units_path(location.scheme, location, referrer: "check_answers") when "type_of_unit" - scheme_location_type_of_unit_path(location.scheme, location) + scheme_location_type_of_unit_path(location.scheme, location, referrer: "check_answers") when "mobility_standards" - scheme_location_mobility_standards_path(location.scheme, location) + scheme_location_mobility_standards_path(location.scheme, location, referrer: "check_answers") when "startdate" - scheme_location_startdate_path(location.scheme, location) + scheme_location_startdate_path(location.scheme, location, referrer: "check_answers") end end diff --git a/app/views/locations/check_answers.html.erb b/app/views/locations/check_answers.html.erb index 4c2eab399..211466bcf 100644 --- a/app/views/locations/check_answers.html.erb +++ b/app/views/locations/check_answers.html.erb @@ -4,7 +4,7 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: :back, + href: scheme_location_startdate_path(@scheme, @location), ) %> <% end %> @@ -26,5 +26,5 @@
<%= govuk_button_to "Add this location", scheme_locations_path(@scheme) %> - <%= govuk_button_link_to "Cancel", new_scheme_location_path(@scheme), secondary: true %> + <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>
diff --git a/app/views/locations/mobility_standards.html.erb b/app/views/locations/mobility_standards.html.erb index e98137818..4023d5675 100644 --- a/app/views/locations/mobility_standards.html.erb +++ b/app/views/locations/mobility_standards.html.erb @@ -3,11 +3,11 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: :back, + href: scheme_location_type_of_unit_path(@scheme, @location), ) %> <% end %> -<%= form_for(@location, method: :patch, url: scheme_location_startdate_path(@scheme, @location)) do |f| %> +<%= form_for(@location, method: :patch, url: scheme_location_mobility_standards_path(@scheme, @location)) do |f| %>
<%= f.govuk_error_summary %> diff --git a/app/views/locations/name.html.erb b/app/views/locations/name.html.erb index a00bad679..56af18469 100644 --- a/app/views/locations/name.html.erb +++ b/app/views/locations/name.html.erb @@ -3,11 +3,11 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: :back, + href: scheme_location_postcode_path(@scheme, @location), ) %> <% end %> -<%= form_for(@location, method: :patch, url: scheme_location_units_path(@scheme, @location)) do |f| %> +<%= form_for(@location, method: :patch, url: scheme_location_name_path(@scheme, @location)) do |f| %>
<%= f.govuk_error_summary %> diff --git a/app/views/locations/postcode.html.erb b/app/views/locations/postcode.html.erb index 2061c5754..e4cfc1723 100644 --- a/app/views/locations/postcode.html.erb +++ b/app/views/locations/postcode.html.erb @@ -3,11 +3,11 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: :back, + href: scheme_locations_path(@scheme), ) %> <% end %> -<%= form_for(@location, method: :patch, url: scheme_location_name_path(@scheme, @location)) do |f| %> +<%= form_for(@location, method: :patch, url: scheme_location_postcode_path(@scheme, @location)) do |f| %>
<%= f.govuk_error_summary %> diff --git a/app/views/locations/startdate.html.erb b/app/views/locations/startdate.html.erb index e0e25ce5f..52b39058a 100644 --- a/app/views/locations/startdate.html.erb +++ b/app/views/locations/startdate.html.erb @@ -3,11 +3,11 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: :back, + href: scheme_location_mobility_standards_path(@scheme, @location), ) %> <% end %> -<%= form_for(@location, method: :patch, url: scheme_location_check_answers_path(@scheme, @location)) do |f| %> +<%= form_for(@location, method: :patch, url: scheme_location_startdate_path(@scheme, @location)) do |f| %>
<%= f.govuk_error_summary %> diff --git a/app/views/locations/type_of_unit.html.erb b/app/views/locations/type_of_unit.html.erb index 4170d4ffa..00faaa085 100644 --- a/app/views/locations/type_of_unit.html.erb +++ b/app/views/locations/type_of_unit.html.erb @@ -3,11 +3,11 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: :back, + href: scheme_location_units_path(@scheme, @location), ) %> <% end %> -<%= form_for(@location, method: :patch, url: scheme_location_mobility_standards_path(@scheme, @location)) do |f| %> +<%= form_for(@location, method: :patch, url: scheme_location_type_of_unit_path(@scheme, @location)) do |f| %>
<%= f.govuk_error_summary %> diff --git a/app/views/locations/units.html.erb b/app/views/locations/units.html.erb index c4bddea5b..a60081ed4 100644 --- a/app/views/locations/units.html.erb +++ b/app/views/locations/units.html.erb @@ -3,11 +3,11 @@ <% content_for :before_content do %> <%= govuk_back_link( text: "Back", - href: :back, + href: scheme_location_name_path(@scheme, @location), ) %> <% end %> -<%= form_for(@location, method: :patch, url: scheme_location_type_of_unit_path(@scheme, @location)) do |f| %> +<%= form_for(@location, method: :patch, url: scheme_location_units_path(@scheme, @location)) do |f| %>
<%= f.govuk_error_summary %> diff --git a/config/routes.rb b/config/routes.rb index e0aac83c8..e58fb1d67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ Rails.application.routes.draw do get "reactivate", to: "locations#reactivate" get "new-reactivation", to: "locations#new_reactivation" get "postcode", to: "locations#postcode" + patch "postcode", to: "locations#postcode" get "name", to: "locations#name" patch "name", to: "locations#name" get "units", to: "locations#units" @@ -76,7 +77,6 @@ Rails.application.routes.draw do get "startdate", to: "locations#startdate" patch "startdate", to: "locations#startdate" get "check-answers", to: "locations#check_answers" - patch "check-answers", to: "locations#check_answers" patch "new-deactivation", to: "locations#new_deactivation" patch "deactivate", to: "locations#deactivate" patch "reactivate", to: "locations#reactivate"