Permalink
Browse files

Replicate, Resolve Bugs, Optimize

  • Loading branch information...
SelenaSmall committed Sep 16, 2015
1 parent 6704589 commit c1778ef3acf4d49a1231c436eb0f488207ea4ba9
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
@@ -0,0 +1,3 @@
// Place all the styles related to the Expense controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,36 @@
class ExpensesController < ApplicationController
before_action :set_expense, only: [:show, :edit, :update, :destroy]

def new
@expense = Expense.new
end

def edit
end

def create
@expense = Expense.new(expense_params)
respond_to do |format|
if @expense.save
format.html { redirect_to edit_expense_path(@expense)}
end
end
end

def update
respond_to do |format|
if @expense.update(expense_params)
format.html { redirect_to edit_expense_path(@expense)}
end
end
end

private
def set_expense
@expense = Expense.find(params[:id])
end

def expense_params
params.require(:expense).permit(:outgoing, :oneoff)
end
end
@@ -33,5 +33,4 @@ def set_income
def income_params
params.require(:income).permit(:wages, :other_income)
end

end
end
@@ -0,0 +1,2 @@
module ExpenseHelper
end
@@ -0,0 +1,5 @@
class Expense < ActiveRecord::Base
def total_expense
outgoing.to_d + oneoff.to_d
end
end
@@ -2,5 +2,4 @@ class Income < ActiveRecord::Base
def total_income
wages.to_d + other_income.to_d
end

end
@@ -0,0 +1,37 @@
<div class="bordered-form">
<%= form_for [@expense] do |f| %>

<h1>expense</h1>
<table>
<tr>
<td class="field-name">
<%= f.label :outgoing %><br>
</td>
<td class="field">
<%= f.number_field :outgoing, :step => 0.01 %>
</td>
</tr>


<tr>
<td class="field-name">
<%= f.label :oneoff %><br>
</td>
<td class="field">
<%= f.number_field :oneoff, :step => 0.01 %>
</td>
</tr>

<tr>
<td class="field-name" id="total-field-name">
<%= f.label :total_expense %><br></td>
<td class="total-output"><%= @expense.total_expense%></td>
</tr>
</table>

<div class="actions">
<%= f.submit %>
</div>

<% end %>
</div>
@@ -0,0 +1,37 @@
<div class="bordered-form">
<%= form_for [@expense] do |f| %>

<h1>Expense</h1>
<table>
<tr>
<td class="field-name">
<%= f.label :outgoing %><br>
</td>
<td class="field">
<%= f.number_field :outgoing, :step => 0.01 %>
</td>
</tr>


<tr>
<td class="field-name">
<%= f.label :oneoff %><br>
</td>
<td class="field">
<%= f.number_field :oneoff, :step => 0.01 %>
</td>
</tr>

<tr>
<td class="field-name" id="total-field-name">
<%= f.label :total_expense %><br></td>
<td class="total-output"><%= @expense.total_expense%></td>
</tr>
</table>

<div class="actions">
<%= f.submit %>
</div>

<% end %>
</div>
@@ -0,0 +1,8 @@
<div class="row">
<div class="col-md-8">
<%= render 'expenses/expenses_index_form' %>

</div>
<div class="col-md-4">
</div>
</div>
@@ -0,0 +1,8 @@
<div class="row">
<div class="col-md-8">
<center><%= render 'expenses/new_expenses_form' %></center>

</div>
<div class="col-md-4">
</div>
</div>
@@ -28,7 +28,7 @@
<td class="total-output"><%= @income.total_income%></td>
</tr>
</table>

<div class="actions">
<%= f.submit %>
</div>
@@ -5,5 +5,4 @@
</div>
<div class="col-md-4">
</div>
</div>

</div>
@@ -45,6 +45,15 @@
<p>This is an app designed to assist individuals in projecting their own budgets, savings and expenses from week to week. It will be built with Ruby on Rails, customized boostrap and postgreSQL assisted by tutorials demonstyrating an understanding of development processes</p>
</center><body>

</div>
</div>
<div class="row">
<div class="col-md-8">

<center><%= render 'expenses/new_expenses_form' %></center>

</div>
<div class="col-md-4">
</div>
</div>
<%= yield %>
@@ -1,7 +1,7 @@
Rails.application.routes.draw do
root 'incomes#new'
resources :incomes, except: [:show, :index]

root 'expenses#new'
#resources :incomes, except: [:show, :index]
resources :expenses, except: [:show, :index]
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

@@ -1,10 +1,9 @@
class CreateIncomes < ActiveRecord::Migration

def change
create_table :incomes do |t|
t.decimal :wages, null: false, default: 0
t.decimal :other_income, null: false, default: 0
t.datetime :value_from
end
end
end
end
@@ -0,0 +1,9 @@
class CreateExpenses < ActiveRecord::Migration
def change
create_table :expenses do |t|
t.decimal :outgoing, null: false, default: 0
t.decimal :oneoff, null: false, default: 0
t.datetime :value_from
end
end
end
@@ -11,11 +11,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150903122041) do
ActiveRecord::Schema.define(version: 20150916090038) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "expenses", force: :cascade do |t|
t.decimal "outgoing", default: 0.0, null: false
t.decimal "oneoff", default: 0.0, null: false
t.datetime "value_from"
end

create_table "incomes", force: :cascade do |t|
t.decimal "wages", default: 0.0, null: false
t.decimal "other_income", default: 0.0, null: false
@@ -0,0 +1,7 @@
require 'test_helper'

class ExpenseControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
outgoing: 9.99
oneoff: 9.99

two:
outgoing: 9.99
oneoff: 9.99
@@ -0,0 +1,7 @@
require 'test_helper'

class ExpenseTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit c1778ef

Please sign in to comment.