Skip to content

Commit 694cb3a

Browse files
committed
Create a new income modal
1 parent 8e501d1 commit 694cb3a

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

Diff for: app/controllers/incomes_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def create
2020
if @income.save
2121
format.html { redirect_to [@mybudget, @incomes], notice: 'income was successfully created.' }
2222
format.json { render :show, status: :created, location: @income }
23+
format.js {redirect_via_turbolinks_to [@mybudget, @incomes]}
2324
else
2425
format.html { render :new }
2526
format.json { render json: @income.errors, status: :unprocessable_entity }

Diff for: app/views/expenses/_form.html.erb

+14-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
<div class="bordered-form">
2-
<%= form_for [@mybudget, @expense] do |f| %>
2+
<%= form_for [@mybudget, @expense] do |f| %>
33

4-
<table>
5-
<tr>
4+
<table>
5+
<tr>
66
<td class="field-name">
7-
<%= f.label :expense %><br>
8-
</td>
9-
<td class="field">
10-
<%= f.text_field :expense %>
11-
</td>
12-
</tr>
13-
14-
<tr>
15-
<td class="field-name">
16-
<%= f.label :amount %><br>
17-
</td>
18-
<td class="field">
19-
<%= f.number_field :amount %>
20-
</td>
21-
</tr>
22-
23-
</table>
24-
7+
<%= f.label :expense %><br>
8+
</td>
9+
<td class="field"><%= f.text_field :expense %></td>
10+
</tr>
11+
<tr>
12+
<td class="field-name"> <%= f.label :amount %><br></td>
13+
<td class="field"><%= f.number_field :amount %></td>
14+
</tr>
15+
</table>
2516
<div class="actions">
26-
<%= f.submit %>
17+
<%= f.submit %>
2718
</div>
28-
29-
<% end %>
19+
<% end %>
3020
</div>

Diff for: app/views/incomes/_modal_form_new.html.erb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<div class="modal-dialog reorder-modal-form">
2+
<div class="modal-content">
3+
<%= bootstrap_form_for([@mybudget, @income], remote: true) do |f| %>
4+
<div class="modal-header">
5+
<h4 class="modal-title">New Income</h4>
6+
</div>
7+
8+
<div class="modal-body">
9+
<table>
10+
<tr>
11+
<td class="field-name">
12+
<%= f.label :income %><br>
13+
</td>
14+
<td class="field"><%= f.text_field :income %></td>
15+
</tr>
16+
<tr>
17+
<td class="field-name"> <%= f.label :amount %><br></td>
18+
<td class="field"><%= f.number_field :amount %></td>
19+
</tr>
20+
</table>
21+
</div>
22+
23+
<div class="modal-footer">
24+
<button type="button" class="btn btn-default" data-dismiss="modal" data-behaviour="form-clear">Cancel</button>
25+
<%= f.submit class: "btn btn-primary", data: { trigger: 'loading' } %>
26+
</div>
27+
<% end %>
28+
</div>
29+
</div>

Diff for: app/views/incomes/new.js.erb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$("#new-income-modal-form").html("<%= j render('incomes/modal_form_new', income: @income) %>");
2+
$('#new-income-modal-form').modal('show')

Diff for: app/views/mybudgets/_incomes.html.erb

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<div class="bordered-form" >
22
<h2>Incomes</h2>
33
<div> - this is going to be an incomes show page which will list all of the incomes and allow the user to add new income values as the week goes. In the long run this will help keep track of projections.</div>
4-
<%= link_to 'Add Income', new_mybudget_income_path(@mybudget, @income) %>
4+
5+
<!--<%= link_to 'Add Income', new_mybudget_income_path(@mybudget, @income) %>-->
6+
<%= link_to new_mybudget_income_path(@mybudget, @income),
7+
remote: true, id: "new-item-link", class: "btn btn-sm btn-default round" do %> New
8+
<%end%>
9+
510

611
<table class="table" >
712
<thead>

Diff for: app/views/mybudgets/show.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@
1919
</div>
2020
<div class="col-md-4">
2121
</div>
22+
23+
<!-- Modal form -->
24+
<div class="modal fade" id='new-income-modal-form' role='dialog'></div>
25+
<!-- Modal form -->
2226
</div>

0 commit comments

Comments
 (0)