Permalink
Browse files

working transfers model

  • Loading branch information...
SelenaSmall committed Sep 20, 2015
1 parent 694cb3a commit 1d4caf0173d5e799e2f944a1f70ed61cdd1d49c0
@@ -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 Transfer controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,51 @@
class TransferController < ApplicationController
before_action :set_mybudget
before_action :set_transfer, only: [:show, :edit, :update, :destroy]

def index
@transfers = @mybudget.transfers.all
end

def new
@transfer = @mybudget.transfers.build
end

def edit
end

def create
@transfer = @mybudget.transfers.build(transfer_params)

respond_to do |format|
if @transfer.save
format.html { redirect_to [@mybudget, @transfers], notice: 'transfer was successfully created.' }
format.json { render :show, status: :created, location: @transfer }
format.js {redirect_via_turbolinks_to [@mybudget, @transfers]}
else
format.html { render :new }
format.json { render json: @transfer.errors, status: :unprocessable_entity }
end
end
end

def update
respond_to do |format|
if @transfer.update(transfer_params)
format.html { redirect_to edit_transfer_path(@transfer)}
end
end
end

private
def set_mybudget
@mybudget = Mybudget.find(params[:mybudget_id])
end

def set_transfer
@transfer = Transfer.find(params[:id])
end

def transfer_params
params.require(:transfer).permit(:transfer, :amount)
end
end
@@ -0,0 +1,2 @@
module TransferHelper
end
@@ -1,4 +1,5 @@
class Mybudget < ActiveRecord::Base
has_many :incomes
has_many :expenses
has_many :transfers
end
@@ -0,0 +1,3 @@
class Transfer < ActiveRecord::Base
belongs_to :mybudget
end
@@ -0,0 +1,32 @@
<div class="bordered-form" >
<h2>transfers</h2>
<div> - this is going to be an transfers show page which will list all of the transfers and allow the user to add new transfer values as the week goes. In the long run this will help keep track of projections.</div>

<!--<%= link_to 'Add transfer', new_mybudget_transfer_path(@mybudget, @transfer) %>-->
<%= link_to new_mybudget_transfer_path(@mybudget, @transfer),
remote: true, id: "new-item-link", class: "btn btn-sm btn-default round" do %> New
<%end%>


<table class="table" >
<thead>
<tr>
<th>transfers</th>
</tr>
</thead>
<tbody>
<% @mybudget.transfers.each do |transfer| %>
<tr>
<div id="transfers"></div>
<td class="table-items"><%= transfer.transfer %></td>
<td class="amount">$<%= transfer.amount %></td>
<td></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<div>TOTAL transfer</div>
<div class="total-output"><%= Transfer.sum(:amount) %>
</div>
</div>
@@ -14,6 +14,7 @@
<div>
<%= render 'mybudgets/incomes' %>
<%= render 'mybudgets/expenses' %>
<%= render 'mybudgets/transfers' %>
</div>
</center>
</div>
@@ -0,0 +1,25 @@
<div class="bordered-form">
<%= form_for [@mybudget, @transfer] do |f| %>

<table>
<tr>
<td class="field-name">
<%= f.label :transfer %><br>
</td>
<td class="field"><%= f.text_field :transfer %></td>
</tr>
<tr>
<td class="field-name"> <%= f.label :amount %><br></td>
<td class="field"><%= f.number_field :amount %></td>
</tr>
<tr>
<td class="field-name" id="total-field-name">
<%= f.label :total_transfer %><br></td>
<td class="total-output"><%= @transfer.total_transfer%></td>
</tr>
</table>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
</div>
@@ -0,0 +1,29 @@
<div class="modal-dialog reorder-modal-form">
<div class="modal-content">
<%= bootstrap_form_for([@mybudget, @transfer], remote: true) do |f| %>
<div class="modal-header">
<h4 class="modal-title">New Transfer</h4>
</div>

<div class="modal-body">
<table>
<tr>
<td class="field-name">
<%= f.label :transfer %><br>
</td>
<td class="field"><%= f.text_field :transfer %></td>
</tr>
<tr>
<td class="field-name"> <%= f.label :amount %><br></td>
<td class="field"><%= f.number_field :amount %></td>
</tr>
</table>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" data-behaviour="form-clear">Cancel</button>
<%= f.submit class: "btn btn-primary", data: { trigger: 'loading' } %>
</div>
<% end %>
</div>
</div>
@@ -0,0 +1,6 @@
<div class="row">
<div class="col-md-8">
<%= render 'transfers/new_transfers_form' %>
<div class="col-md-4">
</div>
</div>
@@ -0,0 +1,2 @@
$("#new-transfer-modal-form").html("<%= j render('transfers/modal_form_new', transfer: @transfer) %>");
$('#new-transfer-modal-form').modal('show')
@@ -4,6 +4,7 @@
resources :mybudgets, except: [:index] do
resources :incomes, except: [:show, :index]
resources :expenses, except: [:show, :index]
resources :transfers, except: [:show, :index]
end
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
@@ -0,0 +1,10 @@
class CreateTransfers < ActiveRecord::Migration
def change
create_table :transfers do |t|
t.belongs_to :mybudget, index: true
t.string :transfer, null: false, limit: 100
t.decimal :amount, null: false, default: 0
t.datetime :value_from
end
end
end
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150917073356) do
ActiveRecord::Schema.define(version: 20150920064544) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -40,4 +40,13 @@
t.datetime "value_from"
end

create_table "transfers", force: :cascade do |t|
t.integer "mybudget_id"
t.string "transfer", limit: 100, null: false
t.decimal "amount", default: 0.0, null: false
t.datetime "value_from"
end

add_index "transfers", ["mybudget_id"], name: "index_transfers_on_mybudget_id", using: :btree

end
@@ -0,0 +1,7 @@
require 'test_helper'

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

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
@@ -0,0 +1,7 @@
require 'test_helper'

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

0 comments on commit 1d4caf0

Please sign in to comment.