From 3ffb6cb62be1ed445202001c37d16c68855dd902 Mon Sep 17 00:00:00 2001 From: Tony Vincent Date: Mon, 8 Jul 2024 14:53:45 +0200 Subject: [PATCH] Add error handling for AccountsController#create (#957) --- app/controllers/accounts_controller.rb | 9 +++------ app/views/accounts/new.html.erb | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 4633d8e9..8544b611 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -3,7 +3,6 @@ class AccountsController < ApplicationController include Filterable before_action :set_account, only: %i[ edit show destroy sync update ] - after_action :sync_account, only: :create def index @institutions = Current.family.institutions @@ -52,8 +51,10 @@ class AccountsController < ApplicationController attributes: account_params.except(:start_date, :start_balance), start_date: account_params[:start_date], start_balance: account_params[:start_balance] - + @account.sync_later redirect_back_or_to account_path(@account), notice: t(".success") + rescue ActiveRecord::RecordInvalid => e + redirect_back_or_to accounts_path, alert: e.record.errors.full_messages.to_sentence end def destroy @@ -94,8 +95,4 @@ class AccountsController < ApplicationController def account_params params.require(:account).permit(:name, :accountable_type, :balance, :start_date, :start_balance, :currency, :subtype, :is_active, :institution_id) end - - def sync_account - @account.sync_later - end end diff --git a/app/views/accounts/new.html.erb b/app/views/accounts/new.html.erb index 878cafc0..1e42a5d6 100644 --- a/app/views/accounts/new.html.erb +++ b/app/views/accounts/new.html.erb @@ -86,7 +86,7 @@ <%= label_tag :add_start_values, t(".optional_start_balance_message"), class: "pl-1 text-sm text-gray-500" %>