Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
working transfers model
- Loading branch information
1 parent
694cb3a
commit 1d4caf0
Showing
18 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module TransferHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class Mybudget < ActiveRecord::Base | ||
has_many :incomes | ||
has_many :expenses | ||
has_many :transfers | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Transfer < ActiveRecord::Base | ||
belongs_to :mybudget | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="row"> | ||
<div class="col-md-8"> | ||
<%= render 'transfers/new_transfers_form' %> | ||
<div class="col-md-4"> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$("#new-transfer-modal-form").html("<%= j render('transfers/modal_form_new', transfer: @transfer) %>"); | ||
$('#new-transfer-modal-form').modal('show') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class TransferControllerTest < ActionController::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class TransferTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |