diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 86d579ec..0a533420 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -1,6 +1,7 @@ class AccountsController < ApplicationController include Filterable before_action :authenticate_user! + before_action :set_account, only: %i[ show update destroy sync ] def new @account = Account.new( @@ -10,7 +11,6 @@ class AccountsController < ApplicationController end def show - @account = Current.family.accounts.find(params[:id]) @balance_series = @account.series(period: @period) @valuation_series = @account.valuations.to_series end @@ -19,8 +19,6 @@ class AccountsController < ApplicationController end def update - @account = Current.family.accounts.find(params[:id]) - if @account.update(account_params.except(:accountable_type)) @account.sync_later if account_params[:is_active] == "1" @@ -50,8 +48,12 @@ class AccountsController < ApplicationController end end + def destroy + @account.destroy! + redirect_to accounts_path, notice: t(".success") + end + def sync - @account = Current.family.accounts.find(params[:id]) @account.sync_later respond_to do |format| @@ -67,6 +69,10 @@ class AccountsController < ApplicationController private + def set_account + @account = Current.family.accounts.find(params[:id]) + end + def account_params params.require(:account).permit(:name, :accountable_type, :balance, :currency, :subtype, :is_active) end diff --git a/app/models/account.rb b/app/models/account.rb index ec039faa..550e0279 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -6,7 +6,6 @@ class Account < ApplicationRecord broadcasts_refreshes belongs_to :family - has_many :balances, dependent: :destroy has_many :valuations, dependent: :destroy has_many :transactions, dependent: :destroy diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index e315c3c5..1b3f9eee 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -17,8 +17,17 @@ <%= lucide_icon("chevron-down", class: "w-5 h-5 text-gray-500") %> -
By deleting this account, you will erase its value history, affecting + various aspects of your overall account. This action will have a direct impact + on your net worth calculations and the account graphs.
After + deletion, there is no way you'll be able to restore the account information + because you'll need to add it as a new account.
" + title: Delete account? default: accept: Confirm body_html: "You will not be able to undo this decision
"