Slide 62
Slide 62 text
/app/controllers/products_controller.rb
1 class ProductsController < ApplicationController
2 respond_to :html, :json, :xml
3
4 def index
5 @products = Product.scoped
6 end
7
8 def new
9 @product = Product.new
10 end
11
12 def create
13 @product = Product.create(params[:product])
14 respond_with @product, location: root_path, only: [:name, :description]
15 end
16
17 def show
18 @product = Product.find(params[:id])
19 end
20
21 def edit
22 @product = Product.find(params[:id])
23 end
24
25 def update
26 @product = Product.update(params[:id], params[:product])
27 respond_with @product, location: root_path, only: [:name, :description]
28 end
29 end
Tuesday, July 17, 12