Redid up to end of Chapter 6 under Rails2.2.2 and Gems 1.3.1, with Product.date_available
[depot.git] / app / controllers / products_controller.rb
1 class ProductsController < ApplicationController
2 # GET /products
3 # GET /products.xml
4 def index
5 @products = Product.find(:all)
6
7 respond_to do |format|
8 format.html # index.html.erb
9 format.xml { render :xml => @products }
10 end
11 end
12
13 # GET /products/1
14 # GET /products/1.xml
15 def show
16 @product = Product.find(params[:id])
17
18 respond_to do |format|
19 format.html # show.html.erb
20 format.xml { render :xml => @product }
21 end
22 end
23
24 # GET /products/new
25 # GET /products/new.xml
26 def new
27 @product = Product.new
28
29 respond_to do |format|
30 format.html # new.html.erb
31 format.xml { render :xml => @product }
32 end
33 end
34
35 # GET /products/1/edit
36 def edit
37 @product = Product.find(params[:id])
38 end
39
40 # POST /products
41 # POST /products.xml
42 def create
43 @product = Product.new(params[:product])
44
45 respond_to do |format|
46 if @product.save
47 flash[:notice] = 'Product was successfully created.'
48 format.html { redirect_to(@product) }
49 format.xml { render :xml => @product, :status => :created, :location => @product }
50 else
51 format.html { render :action => "new" }
52 format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
53 end
54 end
55 end
56
57 # PUT /products/1
58 # PUT /products/1.xml
59 def update
60 @product = Product.find(params[:id])
61
62 respond_to do |format|
63 if @product.update_attributes(params[:product])
64 flash[:notice] = 'Product was successfully updated.'
65 format.html { redirect_to(@product) }
66 format.xml { head :ok }
67 else
68 format.html { render :action => "edit" }
69 format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
70 end
71 end
72 end
73
74 # DELETE /products/1
75 # DELETE /products/1.xml
76 def destroy
77 @product = Product.find(params[:id])
78 @product.destroy
79
80 respond_to do |format|
81 format.html { redirect_to(products_url) }
82 format.xml { head :ok }
83 end
84 end
85 end