diff --git a/app/assets/images/icon-arrow-left.svg b/app/assets/images/icon-arrow-left.svg new file mode 100644 index 00000000..c5d4629c --- /dev/null +++ b/app/assets/images/icon-arrow-left.svg @@ -0,0 +1,3 @@ + diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 3c32bd59..52e05739 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2bfc19d9..f349b44e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/models/depository.rb b/app/models/depository.rb new file mode 100644 index 00000000..64413a49 --- /dev/null +++ b/app/models/depository.rb @@ -0,0 +1,2 @@ +class Depository < Account +end \ No newline at end of file diff --git a/app/views/accounts/index.html.erb b/app/views/accounts/index.html.erb index d2281b00..24ad03e5 100644 --- a/app/views/accounts/index.html.erb +++ b/app/views/accounts/index.html.erb @@ -1,4 +1,8 @@
Find me in app/views/accounts/index.html.erb