2024-02-02 09:05:04 -06:00
|
|
|
class AccountsController < ApplicationController
|
2024-02-02 10:39:16 -06:00
|
|
|
before_action :authenticate_user!
|
|
|
|
|
2024-02-02 09:05:04 -06:00
|
|
|
def index
|
2024-02-02 10:39:16 -06:00
|
|
|
@accounts = current_family.accounts
|
2024-02-02 09:05:04 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
2024-02-02 10:39:16 -06:00
|
|
|
def new_bank
|
|
|
|
@account = DepositoryAccount.new
|
|
|
|
end
|
|
|
|
|
2024-02-02 09:05:04 -06:00
|
|
|
def show
|
|
|
|
end
|
2024-02-02 10:39:16 -06:00
|
|
|
|
|
|
|
def create
|
|
|
|
@account = account_type_class.new(account_params)
|
|
|
|
@account.family = current_family
|
|
|
|
|
|
|
|
if @account.save
|
|
|
|
redirect_to accounts_path
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def account_params
|
|
|
|
params.require(:account).permit(:name, :balance, :type, :subtype)
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_type_class
|
|
|
|
params[:type].constantize
|
|
|
|
rescue
|
|
|
|
Account # Default to Account if type is not provided or invalid
|
|
|
|
end
|
2024-02-02 09:05:04 -06:00
|
|
|
end
|