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

43 lines
769 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 new
end
def new_bank
2024-02-02 11:35:32 -06:00
@account = Depository.new
end
2024-02-02 15:31:32 -06:00
def new_credit
@account = Credit.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
2024-02-02 15:31:32 -06:00
redirect_to root_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