Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign variables #10

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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