1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-31 19:19:38 +02:00

Add ability to delete Account

Issue #571
This commit is contained in:
Mattia Malnis 2024-03-29 12:49:36 +01:00
parent 2181cdd118
commit 8b19b36a9c
4 changed files with 26 additions and 9 deletions

View file

@ -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