Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
294 additions
and
0 deletions.
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,85 @@ | ||
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 |
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 OrdersHelper | ||
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 @@ | ||
class Order < ActiveRecord::Base | ||
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,17 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> | ||
<title>Orders: <%= controller.action_name %></title> | ||
<%= stylesheet_link_tag 'scaffold' %> | ||
</head> | ||
<body> | ||
|
||
<p style="color: green"><%= flash[:notice] %></p> | ||
|
||
<%= yield %> | ||
|
||
</body> | ||
</html> |
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,28 @@ | ||
<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 %> |
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,26 @@ | ||
<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 %> |
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,27 @@ | ||
<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 %> |
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,23 @@ | ||
<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 %> |
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,16 @@ | ||
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 |
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,13 @@ | ||
# 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 |
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,45 @@ | ||
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 |
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,8 @@ | ||
require 'test_helper' | ||
|
||
class OrderTest < ActiveSupport::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
end | ||
end |