diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 486489cbe..5689d6ab6 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -73,19 +73,20 @@ class OrganisationsController < ApplicationController end def new - @resource = Organisation.new + @organisation = Organisation.new @rent_periods = helpers.rent_periods_with_checked_attr render "new", layout: "application" end def create selected_rent_periods = params.require(:organisation).permit(rent_periods: [])[:rent_periods].compact_blank - @resource = Organisation.new(org_params) - if @resource.save + @organisation = Organisation.new(org_params) + if @organisation.save OrganisationRentPeriod.transaction do - selected_rent_periods.each { |period| OrganisationRentPeriod.create!(organisation: @resource, rent_period: period) } + selected_rent_periods.each { |period| OrganisationRentPeriod.create!(organisation: @organisation, rent_period: period) } end - redirect_to organisations_path + flash[:notice] = I18n.t("organisation.created", organisation: @organisation.name) + redirect_to organisation_path @organisation else @rent_periods = helpers.rent_periods_with_checked_attr(checked_periods: selected_rent_periods) render :new, status: :unprocessable_entity diff --git a/app/views/organisations/new.html.erb b/app/views/organisations/new.html.erb index cb62157df..cf58a5de9 100644 --- a/app/views/organisations/new.html.erb +++ b/app/views/organisations/new.html.erb @@ -4,7 +4,7 @@ <%= govuk_back_link(href: :back) %> <% end %> -<%= form_for(@resource, as: :organisation, html: { method: :post }) do |f| %> +<%= form_for(@organisation, as: :organisation, html: { method: :post }) do |f| %>