--- /dev/null
+class LineItemsController < ApplicationController
+ # GET /line_items
+ # GET /line_items.xml
+ def index
+ @line_items = LineItem.find(:all)
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @line_items }
+ end
+ end
+
+ # GET /line_items/1
+ # GET /line_items/1.xml
+ def show
+ @line_item = LineItem.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @line_item }
+ end
+ end
+
+ # GET /line_items/new
+ # GET /line_items/new.xml
+ def new
+ @line_item = LineItem.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @line_item }
+ end
+ end
+
+ # GET /line_items/1/edit
+ def edit
+ @line_item = LineItem.find(params[:id])
+ end
+
+ # POST /line_items
+ # POST /line_items.xml
+ def create
+ @line_item = LineItem.new(params[:line_item])
+
+ respond_to do |format|
+ if @line_item.save
+ flash[:notice] = 'LineItem was successfully created.'
+ format.html { redirect_to(@line_item) }
+ format.xml { render :xml => @line_item, :status => :created, :location => @line_item }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /line_items/1
+ # PUT /line_items/1.xml
+ def update
+ @line_item = LineItem.find(params[:id])
+
+ respond_to do |format|
+ if @line_item.update_attributes(params[:line_item])
+ flash[:notice] = 'LineItem was successfully updated.'
+ format.html { redirect_to(@line_item) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /line_items/1
+ # DELETE /line_items/1.xml
+ def destroy
+ @line_item = LineItem.find(params[:id])
+ @line_item.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(line_items_url) }
+ format.xml { head :ok }
+ end
+ end
+end
--- /dev/null
+class OrdersController < ApplicationController
+ # GET /orders
+ # GET /orders.xml
+ def index
+ @orders = Order.find(:all)
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @orders }
+ end
+ end
+
+ # GET /orders/1
+ # GET /orders/1.xml
+ def show
+ @order = Order.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @order }
+ end
+ end
+
+ # GET /orders/new
+ # GET /orders/new.xml
+ def new
+ @order = Order.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @order }
+ end
+ end
+
+ # GET /orders/1/edit
+ def edit
+ @order = Order.find(params[:id])
+ end
+
+ # POST /orders
+ # POST /orders.xml
+ def create
+ @order = Order.new(params[:order])
+
+ respond_to do |format|
+ if @order.save
+ flash[:notice] = 'Order was successfully created.'
+ format.html { redirect_to(@order) }
+ format.xml { render :xml => @order, :status => :created, :location => @order }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @order.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /orders/1
+ # PUT /orders/1.xml
+ def update
+ @order = Order.find(params[:id])
+
+ respond_to do |format|
+ if @order.update_attributes(params[:order])
+ flash[:notice] = 'Order was successfully updated.'
+ format.html { redirect_to(@order) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @order.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /orders/1
+ # DELETE /orders/1.xml
+ def destroy
+ @order = Order.find(params[:id])
+ @order.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(orders_url) }
+ format.xml { head :ok }
+ end
+ end
+end
--- /dev/null
+module LineItemsHelper
+end
--- /dev/null
+module OrdersHelper
+end
--- /dev/null
+class LineItem < ActiveRecord::Base
+end
--- /dev/null
+class Order < ActiveRecord::Base
+end
--- /dev/null
+<h1>Editing line_item</h1>
+
+<% form_for(@line_item) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :product_id %><br />
+ <%= f.text_field :product_id %>
+ </p>
+ <p>
+ <%= f.label :order_id %><br />
+ <%= f.text_field :order_id %>
+ </p>
+ <p>
+ <%= f.label :quantity %><br />
+ <%= f.text_field :quantity %>
+ </p>
+ <p>
+ <%= f.label :total_price %><br />
+ <%= f.text_field :total_price %>
+ </p>
+ <p>
+ <%= f.submit "Update" %>
+ </p>
+<% end %>
+
+<%= link_to 'Show', @line_item %> |
+<%= link_to 'Back', line_items_path %>
--- /dev/null
+<h1>Listing line_items</h1>
+
+<table>
+ <tr>
+ <th>Product</th>
+ <th>Order</th>
+ <th>Quantity</th>
+ <th>Total price</th>
+ </tr>
+
+<% for line_item in @line_items %>
+ <tr>
+ <td><%=h line_item.product_id %></td>
+ <td><%=h line_item.order_id %></td>
+ <td><%=h line_item.quantity %></td>
+ <td><%=h line_item.total_price %></td>
+ <td><%= link_to 'Show', line_item %></td>
+ <td><%= link_to 'Edit', edit_line_item_path(line_item) %></td>
+ <td><%= link_to 'Destroy', line_item, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New line_item', new_line_item_path %>
--- /dev/null
+<h1>New line_item</h1>
+
+<% form_for(@line_item) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :product_id %><br />
+ <%= f.text_field :product_id %>
+ </p>
+ <p>
+ <%= f.label :order_id %><br />
+ <%= f.text_field :order_id %>
+ </p>
+ <p>
+ <%= f.label :quantity %><br />
+ <%= f.text_field :quantity %>
+ </p>
+ <p>
+ <%= f.label :total_price %><br />
+ <%= f.text_field :total_price %>
+ </p>
+ <p>
+ <%= f.submit "Create" %>
+ </p>
+<% end %>
+
+<%= link_to 'Back', line_items_path %>
--- /dev/null
+<p>
+ <b>Product:</b>
+ <%=h @line_item.product_id %>
+</p>
+
+<p>
+ <b>Order:</b>
+ <%=h @line_item.order_id %>
+</p>
+
+<p>
+ <b>Quantity:</b>
+ <%=h @line_item.quantity %>
+</p>
+
+<p>
+ <b>Total price:</b>
+ <%=h @line_item.total_price %>
+</p>
+
+
+<%= link_to 'Edit', edit_line_item_path(@line_item) %> |
+<%= link_to 'Back', line_items_path %>
--- /dev/null
+<h1>Editing order</h1>
+
+<% form_for(@order) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :address %><br />
+ <%= f.text_area :address %>
+ </p>
+ <p>
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </p>
+ <p>
+ <%= f.label :pay_type %><br />
+ <%= f.text_field :pay_type %>
+ </p>
+ <p>
+ <%= f.submit "Update" %>
+ </p>
+<% end %>
+
+<%= link_to 'Show', @order %> |
+<%= link_to 'Back', orders_path %>
--- /dev/null
+<h1>Listing orders</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Address</th>
+ <th>Email</th>
+ <th>Pay type</th>
+ </tr>
+
+<% for order in @orders %>
+ <tr>
+ <td><%=h order.name %></td>
+ <td><%=h order.address %></td>
+ <td><%=h order.email %></td>
+ <td><%=h order.pay_type %></td>
+ <td><%= link_to 'Show', order %></td>
+ <td><%= link_to 'Edit', edit_order_path(order) %></td>
+ <td><%= link_to 'Destroy', order, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New order', new_order_path %>
--- /dev/null
+<h1>New order</h1>
+
+<% form_for(@order) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :address %><br />
+ <%= f.text_area :address %>
+ </p>
+ <p>
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </p>
+ <p>
+ <%= f.label :pay_type %><br />
+ <%= f.text_field :pay_type %>
+ </p>
+ <p>
+ <%= f.submit "Create" %>
+ </p>
+<% end %>
+
+<%= link_to 'Back', orders_path %>
--- /dev/null
+<p>
+ <b>Name:</b>
+ <%=h @order.name %>
+</p>
+
+<p>
+ <b>Address:</b>
+ <%=h @order.address %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%=h @order.email %>
+</p>
+
+<p>
+ <b>Pay type:</b>
+ <%=h @order.pay_type %>
+</p>
+
+
+<%= link_to 'Edit', edit_order_path(@order) %> |
+<%= link_to 'Back', orders_path %>
--- /dev/null
+class CreateOrders < ActiveRecord::Migration
+ def self.up
+ create_table :orders do |t|
+ t.string :name
+ t.text :address
+ t.string :email
+ t.string :pay_type
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :orders
+ end
+end
--- /dev/null
+class CreateLineItems < ActiveRecord::Migration
+ def self.up
+ create_table :line_items do |t|
+ t.integer :product_id
+ t.integer :order_id
+ t.integer :quantity
+ t.decimal :total_price
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :line_items
+ end
+end
+javac.classpath=
rails.port=3000
source.encoding=UTF-8
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ product_id: 1
+ order_id: 1
+ quantity: 1
+ total_price: 9.99
+
+two:
+ product_id: 1
+ order_id: 1
+ quantity: 1
+ total_price: 9.99
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ name: MyString
+ address: MyText
+ email: MyString
+ pay_type: MyString
+
+two:
+ name: MyString
+ address: MyText
+ email: MyString
+ pay_type: MyString
--- /dev/null
+require 'test_helper'
+
+class LineItemsControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:line_items)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create line_item" do
+ assert_difference('LineItem.count') do
+ post :create, :line_item => { }
+ end
+
+ assert_redirected_to line_item_path(assigns(:line_item))
+ end
+
+ test "should show line_item" do
+ get :show, :id => line_items(:one).id
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => line_items(:one).id
+ assert_response :success
+ end
+
+ test "should update line_item" do
+ put :update, :id => line_items(:one).id, :line_item => { }
+ assert_redirected_to line_item_path(assigns(:line_item))
+ end
+
+ test "should destroy line_item" do
+ assert_difference('LineItem.count', -1) do
+ delete :destroy, :id => line_items(:one).id
+ end
+
+ assert_redirected_to line_items_path
+ end
+end
--- /dev/null
+require 'test_helper'
+
+class OrdersControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:orders)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create order" do
+ assert_difference('Order.count') do
+ post :create, :order => { }
+ end
+
+ assert_redirected_to order_path(assigns(:order))
+ end
+
+ test "should show order" do
+ get :show, :id => orders(:one).id
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => orders(:one).id
+ assert_response :success
+ end
+
+ test "should update order" do
+ put :update, :id => orders(:one).id, :order => { }
+ assert_redirected_to order_path(assigns(:order))
+ end
+
+ test "should destroy order" do
+ assert_difference('Order.count', -1) do
+ delete :destroy, :id => orders(:one).id
+ end
+
+ assert_redirected_to orders_path
+ end
+end
--- /dev/null
+require 'test_helper'
+
+class LineItemTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
--- /dev/null
+require 'test_helper'
+
+class OrderTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end