# enter a customer id here
render :action => 'begin'
session[:total] = 0.00
+ session[:items] = []
end
def customer_ok
def menu
@customer = Customer.find_by_id(session[:customer_id])
@total_price = session[:total]
+ @items = session[:items]
render :action => 'menu'
end
purchase.customer_id = session[:customer_id]
purchase.date = Time.now.to_date
purchase.price = @rentable.calculated_price
- session[:total] += @rentable.calculated_price
purchase.rentable = @rentable
purchase.save!
+ # Add te session variables
+ session[:total] += @rentable.calculated_price
+ session[:items].push @rentable
+
flash[:notice] = "Successfully made purchase"
redirect_to :action => :menu
end
purchase.customer_id = session[:customer_id]
purchase.date = Time.now.to_date
purchase.price = @merchandise.price
- session[:total] += @merchandise.price
purchase.merchandise = @merchandise
purchase.quantity = 1
@merchandise.quantity -= 1
+ # Add to session variables
+ session[:total] += @merchandise.price
+ session[:items].push @merchandise
+
# Save both the merchandise (we changed the quantity) and the purchase to the log
@merchandise.save!
purchase.save!
class Merchandise < ActiveRecord::Base
has_many :merchandise_purchases
- validates_presence_of :name
+ validates_presence_of :title
validates_numericality_of :quantity
validates_numericality_of :price
<% for bitem in @bitems %>
<tr>
<td><%=h bitem.customer.name %></td>
- <td><%=h bitem.merchandise.name %></td>
+ <td><%=h bitem.merchandise.title %></td>
<% for column in Bitem.content_columns %>
<td><%=h bitem.send(column.name) %></td>
<% end %>
<%= error_messages_for 'merchandise' %>
<!--[form:merchandise]-->
-<p><label for="merchandise_name">Name</label><br/>
-<%= text_field 'merchandise', 'name' %></p>
+<p><label for="merchandise_title">Title</label><br/>
+<%= text_field 'merchandise', 'title' %></p>
<p><label for="merchandise_quantity">Quantity</label><br/>
<%= text_field 'merchandise', 'quantity' %></p>
<h1>Purchase Menu</h1>
+<h3>Customer Information</h3>
<ul>
<li>Customer ID: <%= @customer.id %></li>
<li>Customer Name: <%= @customer.name %></li>
<li>Total Price: <%= @total_price %></li>
</ul>
+<h3>Items Purchased</h3>
+<% if @items.empty? %>
+ None
+<% else %>
+<ul>
+<% for item in @items %>
+ <li><%= item.title %></li>
+<% end %>
+</ul>
+<% end %>
+
<ul>
<li><%=link_to 'Rent an Item', :action => 'rent_begin' %></li>
<li><%=link_to 'Buy Merchandise', :action => 'buy_begin' %></li>
--- /dev/null
+class RebuildMerchandisesTable < ActiveRecord::Migration
+
+ # This whole thing is an awful way of doing a column rename
+
+ def self.up
+ drop_table :merchandises
+
+ create_table :merchandises do |t|
+ t.column :title, :string, :null => false
+ t.column :quantity, :integer, :null => false, :default => 0
+ t.column :price, :decimal, :precision => 8, :scale =>2, :default => 0
+ end
+ end
+
+ def self.down
+ drop_table :merchandises
+
+ create_table :merchandises do |t|
+ t.column :name, :string, :null => false
+ t.column :quantity, :integer, :null => false, :default => 0
+ t.column :price, :decimal, :precision => 8, :scale =>2, :default => 0
+ end
+ end
+end
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
-ActiveRecord::Schema.define(:version => 19) do
+ActiveRecord::Schema.define(:version => 20) do
create_table "bitems", :force => true do |t|
t.column "customer_id", :integer, :null => false
end
create_table "merchandises", :force => true do |t|
- t.column "name", :string, :null => false
+ t.column "title", :string, :null => false
t.column "quantity", :integer, :default => 0, :null => false
t.column "price", :decimal, :precision => 8, :scale => 2, :default => 0.0
end