Class: ProductsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/products_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
# File 'app/controllers/products_controller.rb', line 16

def create
  @product = Product.new(params[:product])
  if @product.save
    flash[:notice] = "Successfully created product."
    redirect_to products_url
  else
    render :action => 'new'
  end
end

#destroyObject



41
42
43
44
45
46
# File 'app/controllers/products_controller.rb', line 41

def destroy
  @product = Product.find(params[:id])
  @product.destroy
  flash[:notice] = "Successfully destroyed product."
  redirect_to products_url
end

#editObject



26
27
28
29
# File 'app/controllers/products_controller.rb', line 26

def edit
  @product = Product.find(params[:id])
  render :layout => false
end

#indexObject



3
4
5
# File 'app/controllers/products_controller.rb', line 3

def index
  @products = Product.all
end

#newObject



11
12
13
14
# File 'app/controllers/products_controller.rb', line 11

def new
  @product = Product.new
  render :layout => false
end

#showObject



7
8
9
# File 'app/controllers/products_controller.rb', line 7

def show
  @product = Product.find(params[:id])
end

#updateObject



31
32
33
34
35
36
37
38
39
# File 'app/controllers/products_controller.rb', line 31

def update
  @product = Product.find(params[:id])
  if @product.update_attributes(params[:product])
    flash[:notice] = "Successfully updated product."
    redirect_to products_url
  else
    render :action => 'edit'
  end
end