Permalink
Browse files

Basic Ruby Calculations based on field inputs

  • Loading branch information...
SelenaSmall committed Sep 13, 2015
1 parent 0710fac commit 6704589b936c7c331565b82f199994d12a159670
@@ -10,6 +10,8 @@ gem 'mysql2'

gem 'pg'

gem 'composite_primary_keys'

gem 'datagrid'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
@@ -57,6 +57,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
composite_primary_keys (8.1.1)
activerecord (~> 4.2.0)
datagrid (1.3.9)
rails (>= 3.2.18)
debug_inspector (0.0.2)
@@ -168,6 +170,7 @@ DEPENDENCIES
byebug
cocoon
coffee-rails (~> 4.1.0)
composite_primary_keys
datagrid
jbuilder (~> 2.0)
jquery-rails
@@ -46,6 +46,20 @@
.field {
padding: 10px;
padding-left: 250px;

#income_other_income {
text-align: right;
}
#income_wages {
text-align: right;
}
}

.total-output {
text-align: right;
padding-right: 20px;
font-style: bold;
font-size: 40px
}

.actions {
@@ -63,8 +77,4 @@
#total-field-name {
font-size: 25px;
color: #1F3D99;
}

#income_income_total {
background-color: lightyellow;
}
@@ -31,7 +31,7 @@ def set_income
end

def income_params
params.require(:income).permit(:wages, :other_income, :income_total)
params.require(:income).permit(:wages, :other_income)
end

end
@@ -1,18 +1,6 @@
class Income < ActiveRecord::Base
# include ActiveModel::Model
def total_income
wages.to_d + other_income.to_d
end

# attr_accessor :wages, :other_income, :total_income

# def set_income_total
# @incomes.each do |income|
# a = incomes.wages
# b = incomes.other_income
# c = incomes.total_income
# end
# @set_total_income == (a+b)

# end

end


end
@@ -8,7 +8,7 @@
<%= f.label :wages %><br>
</td>
<td class="field">
<%= f.number_field :wages %>
<%= f.number_field :wages, :step => 0.01 %>
</td>
</tr>

@@ -18,17 +18,14 @@
<%= f.label :other_income %><br>
</td>
<td class="field">
<%= f.number_field :other_income %>
<%= f.number_field :other_income, :step => 0.01 %>
</td>
</tr>

<tr>
<td class="field-name" id="total-field-name">
<%= f.label :income_total %><br>
</td>
<td class="field" id="total-field">
<%= f.number_field :income_total %>
</td>
<%= f.label :total_income %><br></td>
<td class="total-output"><%= @income.total_income%></td>
</tr>
</table>

@@ -8,7 +8,7 @@
<%= f.label :wages %><br>
</td>
<td class="field">
<%= f.number_field :wages %>
<%= f.number_field :wages, :step => 0.01 %>
</td>
</tr>

@@ -18,17 +18,14 @@
<%= f.label :other_income %><br>
</td>
<td class="field">
<%= f.number_field :other_income %>
<%= f.number_field :other_income, :step => 0.01 %>
</td>
</tr>

<tr>
<td class="field-name" id="total-field-name">
<%= f.label :income_total %><br>
</td>
<td class="field" id="total-field">
<%= f.number_field :income_total %>
</td>
<%= f.label :total_income %><br></td>
<td class="total-output"><%= @income.total_income%></td>
</tr>
</table>

@@ -13,7 +13,7 @@ development:
<<: *default
adapter: postgresql
encoding: unicode
database: reservations
database: my_budget
pool: 5
username: selenasmall
password:
@@ -1,11 +1,10 @@
class CreateIncomes < ActiveRecord::Migration

def change
create_table :incomes do |t|
t.integer :wages
t.integer :other_income
t.integer :income_total

t.timestamps null: false
t.decimal :wages, null: false, default: 0
t.decimal :other_income, null: false, default: 0
t.datetime :value_from
end
end
end
@@ -17,11 +17,9 @@
enable_extension "plpgsql"

create_table "incomes", force: :cascade do |t|
t.integer "wages"
t.integer "other_income"
t.integer "income_total"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.decimal "wages", default: 0.0, null: false
t.decimal "other_income", default: 0.0, null: false
t.datetime "value_from"
end

end

0 comments on commit 6704589

Please sign in to comment.