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:
parent
80f68b657c
commit
f8174990ca
5 changed files with 27 additions and 29 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue