1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Fix accountable type references in new account flow (#395)

* Fix accountable type references in new account flow

* Add remaining references

* Refactor accountable type checking

* Refactor new account template to use account

* Refactor account create action

* Refactor account sidebar
This commit is contained in:
Josh Brown 2024-02-09 14:26:54 +00:00 committed by GitHub
parent 80f68b657c
commit f8174990ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 27 additions and 29 deletions

View file

@ -2,23 +2,18 @@ class AccountsController < ApplicationController
before_action :authenticate_user!
def new
if params[:type].blank? || Account.accountable_types.include?("Account::#{params[:type]}")
@account = if params[:type].blank?
Account.new
else
Account.new(accountable_type: "Account::#{params[:type]}", balance: nil)
end
else
head :not_found
end
@account = Account.new(
balance: nil,
accountable: Accountable.from_type(params[:type])&.new
)
end
def show
end
def create
@account = Current.family.accounts.build(account_params)
@account.accountable = account_params[:accountable_type].constantize.new
@account = Current.family.accounts.build(account_params.except(:accountable_type))
@account.accountable = Accountable.from_type(account_params[:accountable_type])&.new
if @account.save
redirect_to accounts_path, notice: t(".success")
@ -32,12 +27,4 @@ class AccountsController < ApplicationController
def account_params
params.require(:account).permit(:name, :accountable_type, :balance, :balance_cents, :subtype)
end
def account_type_class
if params[:type].present? && Account.accountable_types.include?(params[:type])
params[:type].constantizes
else
Account # Default to Account if type is not provided or invalid
end
end
end