Skip to content

Commit

Permalink
add files generated by scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
kyanny committed Jan 19, 2010
1 parent 35a9ab6 commit c1ac90d
Show file tree
Hide file tree
Showing 14 changed files with 330 additions and 0 deletions.
85 changes: 85 additions & 0 deletions depot/app/controllers/products_controller.rb
@@ -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
2 changes: 2 additions & 0 deletions depot/app/helpers/products_helper.rb
@@ -0,0 +1,2 @@
module ProductsHelper
end
2 changes: 2 additions & 0 deletions depot/app/models/product.rb
@@ -0,0 +1,2 @@
class Product < ActiveRecord::Base
end
17 changes: 17 additions & 0 deletions depot/app/views/layouts/products.html.erb
@@ -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>
24 changes: 24 additions & 0 deletions depot/app/views/products/edit.html.erb
@@ -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 %>
24 changes: 24 additions & 0 deletions depot/app/views/products/index.html.erb
@@ -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 %>
23 changes: 23 additions & 0 deletions depot/app/views/products/new.html.erb
@@ -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 %>
18 changes: 18 additions & 0 deletions depot/app/views/products/show.html.erb
@@ -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 %>
2 changes: 2 additions & 0 deletions depot/config/routes.rb
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :products

# The priority is based upon order of creation: first created -> highest priority.

# Sample of regular route:
Expand Down
15 changes: 15 additions & 0 deletions depot/db/migrate/20100119095254_create_products.rb
@@ -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
54 changes: 54 additions & 0 deletions depot/public/stylesheets/scaffold.css
@@ -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;
}

11 changes: 11 additions & 0 deletions depot/test/fixtures/products.yml
@@ -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
45 changes: 45 additions & 0 deletions depot/test/functional/products_controller_test.rb
@@ -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
8 changes: 8 additions & 0 deletions depot/test/unit/product_test.rb
@@ -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

0 comments on commit c1ac90d

Please sign in to comment.