X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=app%2Fcontrollers%2Fproducts_controller.rb;fp=app%2Fcontrollers%2Fproducts_controller.rb;h=1685ca58ae1002bd26a6e812a62ec4f94c1e41fe;hb=e580d4626176c8deb6f44fec7e66f980b5923b29;hp=0000000000000000000000000000000000000000;hpb=28668145b30d983f624bebb24e9ac9c23d9b13cd;p=depot.git diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000..1685ca5 --- /dev/null +++ b/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