Skip to content

Commit

Permalink
Assign variables (#10)
Browse files Browse the repository at this point in the history
* Add concern to build instance variables

* Lint
  • Loading branch information
neb417 authored Nov 7, 2023
1 parent d0a20ec commit 556a050
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
15 changes: 15 additions & 0 deletions app/controllers/concerns/dashboard_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module DashboardConcern
extend ActiveSupport::Concern

included do
end

def build_instance_variables
@incomes = Income.order_by_type
@fixed_expenses = FixedExpense.get_ordered
@totals = FixedExpense.total_costs
@federal_tax_brackets = FederalTaxBracket.order_by_range
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
end
end
8 changes: 2 additions & 6 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
class DashboardController < ApplicationController
include DashboardConcern
def index
@incomes = Income.order_by_type
@fixed_expenses = FixedExpense.get_ordered
@totals = FixedExpense.total_costs
@federal_tax_brackets = FederalTaxBracket.order_by_range
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
build_instance_variables
end
end
15 changes: 4 additions & 11 deletions app/controllers/fixed_expenses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class FixedExpensesController < ApplicationController
include DashboardConcern
before_action :set_fixed_expense, only: %i[show edit update destroy]

# GET /fixed_expenses or /fixed_expenses.json
Expand All @@ -25,10 +26,7 @@ def create

respond_to do |format|
if @fixed_expense.save
@totals = FixedExpense.total_costs
@fixed_expenses = FixedExpense.get_ordered
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
build_instance_variables
format.html { redirect_to root_path, notice: "Fixed expense was successfully created." }
format.turbo_stream
else
Expand All @@ -42,9 +40,7 @@ def create
def update
respond_to do |format|
if @fixed_expense.update_from_dashboard(params: params[:fixed_expense])
@totals = FixedExpense.total_costs
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
build_instance_variables
format.html { redirect_to root_path, notice: "Fixed expense was successfully updated." }
format.turbo_stream
else
Expand All @@ -57,10 +53,7 @@ def update
# DELETE /fixed_expenses/1 or /fixed_expenses/1.json
def destroy
@fixed_expense.destroy
@totals = FixedExpense.total_costs
@fixed_expenses = FixedExpense.get_ordered
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
build_instance_variables
respond_to do |format|
format.html { redirect_to fixed_expenses_path, notice: "Fixed expense was successfully destroyed." }
format.turbo_stream
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/incomes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class IncomesController < ApplicationController
include DashboardConcern
before_action :set_income, only: %i[show edit update destroy]

# GET /incomes or /incomes.json
Expand Down Expand Up @@ -38,9 +39,7 @@ def create
def update
respond_to do |format|
if @income.update_from_dashboard(params: params)
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
@totals = FixedExpense.total_costs
build_instance_variables
format.html { redirect_to root_path, notice: "Income was successfully updated." }
format.turbo_stream
else
Expand Down

0 comments on commit 556a050

Please sign in to comment.