diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index 2473c38c1..a653ec0fa 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -29,6 +29,11 @@ class OrganisationRelationshipsController < ApplicationController end def create + @resource = OrganisationRelationship.new + if params["related_organisation_id"] == nil + @resource.errors.add :housing_providers, "Select a housing provider" + return + end @resource = OrganisationRelationship.new(child_organisation_id: @organisation.id, parent_organisation_id: related_organisation_params, relationship_type: 0) @resource.save! redirect_to housing_providers_organisation_path @@ -40,10 +45,6 @@ private @organisation ||= Organisation.find(params[:id]) end - def related_organisation - Organisation.find(params[:related_organisation_id]) - end - def related_organisation_params params.require(:related_organisation_id) end diff --git a/app/views/organisation_relationships/add_housing_provider.html.erb b/app/views/organisation_relationships/add_housing_provider.html.erb index a89a4688e..7409c36d5 100644 --- a/app/views/organisation_relationships/add_housing_provider.html.erb +++ b/app/views/organisation_relationships/add_housing_provider.html.erb @@ -1,6 +1,5 @@ -<%= form_with url: housing_providers_organisation_path, method: "post", local: true do |f| %> - <%# remove_other_page_errors(@log, @page) %> - <%#= f.govuk_error_summary %> +<%= form_with model: @organisation, url: housing_providers_organisation_path, method: "post", local: true do |f| %> + <%= f.govuk_error_summary %> <% if current_user.support? %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>