mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
New bank addition (mostly hashing out STI bits)
Messy and gross. Will get cleaned up in the next couple of commits.
This commit is contained in:
parent
9014c8e615
commit
3bf7b47040
8 changed files with 86 additions and 2 deletions
|
@ -1,10 +1,40 @@
|
|||
class AccountsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
|
||||
def index
|
||||
@accounts = current_family.accounts
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def new_bank
|
||||
@account = DepositoryAccount.new
|
||||
end
|
||||
|
||||
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
|
||||
params[:type].constantize
|
||||
rescue
|
||||
Account # Default to Account if type is not provided or invalid
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,11 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
helper_method :current_user
|
||||
|
||||
def current_family
|
||||
current_user.family
|
||||
end
|
||||
helper_method :current_family
|
||||
|
||||
def authenticate_user_from_session
|
||||
User.find_by(id: session[:user_id])
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue