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
14 changed files
with
330 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 ProductsController < ApplicationController | ||
# GET /products | ||
# GET /products.xml | ||
def index | ||
@products = Product.find(:all) | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.xml { render :xml => @products } | ||
end | ||
end | ||
|
||
# GET /products/1 | ||
# GET /products/1.xml | ||
def show | ||
@product = Product.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.xml { render :xml => @product } | ||
end | ||
end | ||
|
||
# GET /products/new | ||
# GET /products/new.xml | ||
def new | ||
@product = Product.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @product } | ||
end | ||
end | ||
|
||
# GET /products/1/edit | ||
def edit | ||
@product = Product.find(params[:id]) | ||
end | ||
|
||
# POST /products | ||
# POST /products.xml | ||
def create | ||
@product = Product.new(params[:product]) | ||
|
||
respond_to do |format| | ||
if @product.save | ||
flash[:notice] = 'Product was successfully created.' | ||
format.html { redirect_to(@product) } | ||
format.xml { render :xml => @product, :status => :created, :location => @product } | ||
else | ||
format.html { render :action => "new" } | ||
format.xml { render :xml => @product.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /products/1 | ||
# PUT /products/1.xml | ||
def update | ||
@product = Product.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @product.update_attributes(params[:product]) | ||
flash[:notice] = 'Product was successfully updated.' | ||
format.html { redirect_to(@product) } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @product.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /products/1 | ||
# DELETE /products/1.xml | ||
def destroy | ||
@product = Product.find(params[:id]) | ||
@product.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(products_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 ProductsHelper | ||
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 Product < 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>Products: <%= 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,24 @@ | ||
<h1>Editing product</h1> | ||
|
||
<% form_for(@product) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :title %><br /> | ||
<%= f.text_field :title %> | ||
</p> | ||
<p> | ||
<%= f.label :description %><br /> | ||
<%= f.text_area :description %> | ||
</p> | ||
<p> | ||
<%= f.label :image_url %><br /> | ||
<%= f.text_field :image_url %> | ||
</p> | ||
<p> | ||
<%= f.submit "Update" %> | ||
</p> | ||
<% end %> | ||
<%= link_to 'Show', @product %> | | ||
<%= link_to 'Back', products_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,24 @@ | ||
<h1>Listing products</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Title</th> | ||
<th>Description</th> | ||
<th>Image url</th> | ||
</tr> | ||
|
||
<% for product in @products %> | ||
<tr> | ||
<td><%=h product.title %></td> | ||
<td><%=h product.description %></td> | ||
<td><%=h product.image_url %></td> | ||
<td><%= link_to 'Show', product %></td> | ||
<td><%= link_to 'Edit', edit_product_path(product) %></td> | ||
<td><%= link_to 'Destroy', product, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New product', new_product_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 @@ | ||
<h1>New product</h1> | ||
|
||
<% form_for(@product) do |f| %> | ||
<%= f.error_messages %> | ||
|
||
<p> | ||
<%= f.label :title %><br /> | ||
<%= f.text_field :title %> | ||
</p> | ||
<p> | ||
<%= f.label :description %><br /> | ||
<%= f.text_area :description %> | ||
</p> | ||
<p> | ||
<%= f.label :image_url %><br /> | ||
<%= f.text_field :image_url %> | ||
</p> | ||
<p> | ||
<%= f.submit "Create" %> | ||
</p> | ||
<% end %> | ||
<%= link_to 'Back', products_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,18 @@ | ||
<p> | ||
<b>Title:</b> | ||
<%=h @product.title %> | ||
</p> | ||
|
||
<p> | ||
<b>Description:</b> | ||
<%=h @product.description %> | ||
</p> | ||
|
||
<p> | ||
<b>Image url:</b> | ||
<%=h @product.image_url %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_product_path(@product) %> | | ||
<%= link_to 'Back', products_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,15 @@ | ||
class CreateProducts < ActiveRecord::Migration | ||
def self.up | ||
create_table :products do |t| | ||
t.string :title | ||
t.text :description | ||
t.string :image_url | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :products | ||
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,54 @@ | ||
body { background-color: #fff; color: #333; } | ||
|
||
body, p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; | ||
} | ||
|
||
a { color: #000; } | ||
a:visited { color: #666; } | ||
a:hover { color: #fff; background-color:#000; } | ||
|
||
.fieldWithErrors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; | ||
} | ||
|
||
#errorExplanation { | ||
width: 400px; | ||
border: 2px solid red; | ||
padding: 7px; | ||
padding-bottom: 12px; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
#errorExplanation h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
#errorExplanation p { | ||
color: #333; | ||
margin-bottom: 0; | ||
padding: 5px; | ||
} | ||
|
||
#errorExplanation ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} | ||
|
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,11 @@ | ||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
title: MyString | ||
description: MyText | ||
image_url: MyString | ||
|
||
two: | ||
title: MyString | ||
description: MyText | ||
image_url: 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 ProductsControllerTest < ActionController::TestCase | ||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
assert_not_nil assigns(:products) | ||
end | ||
|
||
test "should get new" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "should create product" do | ||
assert_difference('Product.count') do | ||
post :create, :product => { } | ||
end | ||
|
||
assert_redirected_to product_path(assigns(:product)) | ||
end | ||
|
||
test "should show product" do | ||
get :show, :id => products(:one).id | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get :edit, :id => products(:one).id | ||
assert_response :success | ||
end | ||
|
||
test "should update product" do | ||
put :update, :id => products(:one).id, :product => { } | ||
assert_redirected_to product_path(assigns(:product)) | ||
end | ||
|
||
test "should destroy product" do | ||
assert_difference('Product.count', -1) do | ||
delete :destroy, :id => products(:one).id | ||
end | ||
|
||
assert_redirected_to products_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 ProductTest < ActiveSupport::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
end | ||
end |