Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GoBug/app/controllers/expenses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ExpensesController < ApplicationController
def index
@trip = Trip.find(params[:trip_id])
@expenses = @trip.expenses.all
@is_wishlist = false
end

# GET /expenses/1
Expand Down
39 changes: 39 additions & 0 deletions GoBug/app/controllers/wishlist_items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class WishlistItemsController < ApplicationController

def new
@wishlistitem = WishlistItem.new
end

def create
@current_user = current_user
@wishlist = Wishlist.find(params[:wishlist_id])
# @wishlistitem = WishlistItem.new(wishlist_id: params[:wishlist_id], expense_id: params[:expense_id])
@wishlistitem = WishlistItem.new(wishlist_items_params)

respond_to do |format|
if @wishlistitem.save
format.html { redirect_to wishlist_path(@wishlist), notice: 'Wishlist Item was successfully created.' }
#format.html { redirect_to @trip, notice: 'Trip was successfully created.' }
format.json { render :show, status: :created, location: @wishlist }
else
format.html { render :new }
format.json { render json: @wishlist.errors, status: :unprocessable_entity }
end
end
end

def destroy
@wishlist_item = WishlistItem.where(wishlist_id: params[:wishlist_id], expense_id: params[:expense_id]).first
@wishlist_item.destroy
respond_to do |format|
format.html { redirect_to wishlists_url, notice: 'Wishlist was successfully destroyed.' }
format.json { head :no_content }
end
end

private
def wishlist_items_params
params.permit(:expense_id, :wishlist_id)
end

end
2 changes: 2 additions & 0 deletions GoBug/app/controllers/wishlists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def index
# GET /wishlists/1
# GET /wishlists/1.json
def show
@expenses = @wishlist.expenses
@is_wishlist = true
end

# GET /wishlists/new
Expand Down
2 changes: 2 additions & 0 deletions GoBug/app/models/expense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ class Expense < ActiveRecord::Base
belongs_to :trip
belongs_to :currency
belongs_to :location
has_many :wishlist_items
has_many :wishlists, through: :wishlist_items
has_one :user, through: :trip
end
5 changes: 3 additions & 2 deletions GoBug/app/models/wishlist.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Wishlist < ActiveRecord::Base
has_many :wishlist_items
has_many :items, through: :wishlist_items
has_many :expenses, through: :wishlist_items
belongs_to :user
end

end
2 changes: 1 addition & 1 deletion GoBug/app/models/wishlist_item.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class WishlistItem< ActiveRecord::Base
belongs_to :wishlist
belongs_to :item
belongs_to :expense
end
31 changes: 31 additions & 0 deletions GoBug/app/views/expenses/_expense_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<table>
<thead>
<tr>
<th>Cost</th>
<th>Description</th>
<th>Category</th>
<th>Date</th>
<th>Location</th>
<th colspan="2"></th>
</tr>
</thead>

<tbody>
<% @expenses.each do |expense| %>
<tr>
<td><%= expense.cost %></td>
<td><%= link_to expense.description, expense_path(expense) %></td>
<td><%= expense.category.name %></td>
<td><%= expense.date %></td>
<td><%= expense.location.name %></td>
<td><%= link_to 'Edit', edit_expense_path(expense) %></td>
<td><%= link_to 'Destroy', expense_path(expense), method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% if @is_wishlist == false %>
<td><%= button_to 'Add to Wishlist', {:controller => :wishlist_items, :action => 'create', :expense_id => expense.id, :wishlist_id => 1 }, :method => :create %></td>
<% else %>
<td><%= button_to 'Remove', {:controller => :wishlist_items, :action => 'destroy', :expense_id => expense.id, :wishlist_id => 1 }, :method => :delete %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
27 changes: 1 addition & 26 deletions GoBug/app/views/expenses/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
<h1>Listing expenses</h1>

<table>
<thead>
<tr>
<th>Cost</th>
<th>Description</th>
<th>Category</th>
<th>Date</th>
<th>Location</th>
<th colspan="2"></th>
</tr>
</thead>

<tbody>
<% @expenses.each do |expense| %>
<tr>
<td><%= expense.cost %></td>
<td><%= link_to expense.description, expense_path(expense) %></td>
<td><%= expense.category.name %></td>
<td><%= expense.date %></td>
<td><%= expense.location.name %></td>
<td><%= link_to 'Edit', edit_expense_path(expense) %></td>
<td><%= link_to 'Destroy', expense_path(expense), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<%= render 'expense_table' %>

<br>
26 changes: 26 additions & 0 deletions GoBug/app/views/wishlists/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%= form_for(@wishlist) do |f| %>
<% if @wishlist.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@wishlist.errors.count, "error") %> prohibited this wishlist from being saved:</h2>

<ul>
<% @wishlist.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :budget %><br>
<%= f.number_field :budget %>
</div>

<div class="actions">
<%= f.submit %>
</div>
<% end %>
1 change: 1 addition & 0 deletions GoBug/app/views/wishlists/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form' %>
28 changes: 28 additions & 0 deletions GoBug/app/views/wishlists/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<h1>All Users' Wishlists</h1>

<table>
<thead>
<tr>
<th>User</th>
<th>Name</th>
<th>Budget</th>
<th colspan="2"></th>
</tr>
</thead>

<tbody>
<% @wishlists.each do |wishlist| %>
<tr>
<td><%= wishlist.user.username %></td>
<td><%= link_to wishlist.name, wishlist_path(wishlist) %></td>
<td><%= wishlist.budget %></td>
<td><%= link_to 'Edit', edit_wishlist_path(wishlist) %></td>
<td><%= link_to 'Destroy', wishlist, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Wishlist', new_wishlist_path %>
4 changes: 4 additions & 0 deletions GoBug/app/views/wishlists/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>New Wishlist</h1>
<%= render 'form' %>

<%= link_to 'Back', wishlists_path %>
16 changes: 16 additions & 0 deletions GoBug/app/views/wishlists/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Name:</strong>
<%= @wishlist.name %>
</p>

<p>
<strong>Budget:</strong>
<%= @wishlist.budget %>
</p>

<%= render '/expenses/expense_table' %>

<%= link_to 'Edit', edit_wishlist_path(@wishlist) %> |
<%= link_to 'Back', wishlists_path %>
2 changes: 2 additions & 0 deletions GoBug/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

resources :wishlists

resources :wishlist_items

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

Expand Down
2 changes: 1 addition & 1 deletion GoBug/db/migrate/20141018044854_create_trips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def change
create_table :trips do |t|
t.references :user, index: true, null: false
t.string :name, null: false
t.text :description, null: false
t.text :description
t.integer :budget, null: false
t.boolean :is_published, default: false
t.boolean :is_private, default: false
Expand Down
2 changes: 1 addition & 1 deletion GoBug/db/migrate/20141018134647_create_wishlist_items.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateWishlistItems < ActiveRecord::Migration
def change
create_table :wishlist_items do |t|
t.references :item
t.references :expense
t.references :wishlist

t.timestamps
Expand Down
4 changes: 2 additions & 2 deletions GoBug/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
create_table "trips", force: true do |t|
t.integer "user_id", null: false
t.string "name", null: false
t.text "description", null: false
t.text "description"
t.integer "budget", null: false
t.boolean "is_published", default: false
t.boolean "is_private", default: false
Expand All @@ -76,7 +76,7 @@
end

create_table "wishlist_items", force: true do |t|
t.integer "item_id"
t.integer "expense_id"
t.integer "wishlist_id"
t.datetime "created_at"
t.datetime "updated_at"
Expand Down
11 changes: 11 additions & 0 deletions GoBug/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@
shopping = Category.create(name:"Shopping")
activities = Category.create(name:"Activities")
misc = Category.create(name:"Miscellaneous")

trip = Trip.create(user: sarah, name: "Texas Vacation", budget: "100")
trip1 = Trip.create(user: nic, name: "Texas Paradise", budget: "1000")

whattaburger = Expense.create(cost:30.50, description:"Lunch at whattaburger", category: food, trip: trip, date: Time.now, location: houston)
rodeo = Expense.create(cost:112, description:"Rodeo night show", category: activities, trip: trip, date: Time.now, location: houston)
barn = Expense.create(cost:400, description:"Hotel stay at the Barn", category: housing, trip: trip, date: Time.now, location: austin)

sad_happy_masks = Expense.create(cost:44.99, description:"Sad face, happy face wall decor", category: shopping, trip: trip1, date: Time.now, location: houston)
improv_class = Expense.create(cost:432, description:"Week long improv class", category: activities, trip: trip1, date: Time.now, location: dallas)
mcdonalds = Expense.create(cost:12, description:"McDonalds dinner", category: food, trip: trip1, date: Time.now, location: dallas)