2025-04-14 11:40:34 -04:00
|
|
|
class HoldingsController < ApplicationController
|
2024-10-09 14:59:18 -04:00
|
|
|
before_action :set_holding, only: %i[show destroy]
|
2024-07-25 16:46:04 -04:00
|
|
|
|
|
|
|
def index
|
2024-11-27 16:01:50 -05:00
|
|
|
@account = Current.family.accounts.find(params[:account_id])
|
2024-07-25 16:46:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
2024-10-09 14:59:18 -04:00
|
|
|
def destroy
|
2025-03-05 12:21:17 -05:00
|
|
|
if @holding.account.plaid_account_id.present?
|
|
|
|
flash[:alert] = "You cannot delete this holding"
|
|
|
|
else
|
|
|
|
@holding.destroy_holding_and_entries!
|
|
|
|
flash[:notice] = t(".success")
|
|
|
|
end
|
2024-07-25 16:46:04 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_back_or_to account_path(@holding.account) }
|
|
|
|
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, account_path(@holding.account)) }
|
2024-07-25 16:46:04 -04:00
|
|
|
end
|
2024-11-27 16:01:50 -05:00
|
|
|
end
|
2024-07-25 16:46:04 -04:00
|
|
|
|
2024-11-27 16:01:50 -05:00
|
|
|
private
|
2024-07-25 16:46:04 -04:00
|
|
|
def set_holding
|
2024-12-12 08:56:52 -05:00
|
|
|
@holding = Current.family.holdings.find(params[:id])
|
2024-07-25 16:46:04 -04:00
|
|
|
end
|
|
|
|
end
|