1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-20 05:39:39 +02:00
Maybe/app/controllers/accounts_controller.rb
Ricardo Siqueira de Oliveira Leite c8a659694d
Start I18n Internationalization setup (#276)
* start internationalization_setup

* add passwords views translations

* add account views translations

* fix translations

* temporary disable i18n used key
2024-02-06 11:58:17 -06:00

43 lines
1.1 KiB
Ruby

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
end
def show
end
def create
@account = Current.family.accounts.build(account_params)
@account.accountable = account_params[:accountable_type].constantize.new
if @account.save
redirect_to accounts_path, notice: t(".success")
else
render "new", status: :unprocessable_entity
end
end
private
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