1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/app/controllers/accounts_controller.rb

43 lines
789 B
Ruby
Raw Normal View History

2024-02-02 09:05:04 -06:00
class AccountsController < ApplicationController
before_action :authenticate_user!
2024-02-02 09:05:04 -06:00
def index
@accounts = current_family.accounts
2024-02-02 09:05:04 -06:00
end
def new
end
def new_bank
@account = DepositoryAccount.new
end
2024-02-02 09:05:04 -06:00
def show
end
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
if params[:type].present? && Account::VALID_ACCOUNT_TYPES.include?(params[:type])
2024-02-02 16:54:15 +00:00
params[:type].constantizes
else
Account # Default to Account if type is not provided or invalid
end
end
2024-02-02 09:05:04 -06:00
end