Class: Adminpanel::ProductsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#handle_unverified_request, #signed_in_user

Methods included from SessionsHelper

#current_user, #current_user=, #sign_in, #sign_out, #signed_in?

Instance Method Details

#createObject

POST /admin/products POST /admin/products.json



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/adminpanel/products_controller.rb', line 45

def create
  @product = Product.new(params[:product])

  respond_to do |format|
    if @product.save
      format.html { redirect_to product_path(@product), :notice => 'Product was successfully created.' }
      format.json { render :json =>  product_path(@product), :status => :created, :location => @product }
    else
      @categories = Category.all.collect{|c| [ c.name, c.id ] }
      format.html { render :action => "new" }
      format.json { render :json => @product.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /admin/products/1 DELETE /admin/products/1.json



78
79
80
81
82
83
84
85
86
# File 'app/controllers/adminpanel/products_controller.rb', line 78

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

  respond_to do |format|
    format.html { redirect_to products_url }
    format.json { head :no_content }
  end
end

#editObject

GET /admin/products/1/edit



38
39
40
41
# File 'app/controllers/adminpanel/products_controller.rb', line 38

def edit
  @product = Product.find(params[:id])
  @categories = Category.all.collect{|c| [ c.name, c.id ] }
end

#indexObject

GET /admin/products GET /admin/products.json



5
6
7
8
9
10
11
12
# File 'app/controllers/adminpanel/products_controller.rb', line 5

def index
  @products = Product.all

  respond_to do |format|
    format.html # index.html.erb
    format.json { render :json => @products }
  end
end

#newObject

GET /admin/products/new GET /admin/products/new.json



27
28
29
30
31
32
33
34
35
# File 'app/controllers/adminpanel/products_controller.rb', line 27

def new
  @product = Product.new
  @categories = Category.all.collect{|c| [ c.name, c.id ] }

  respond_to do |format|
    format.html # new.html.erb
    format.json { render :json => @product }
  end
end

#showObject

GET /admin/products/1 GET /admin/products/1.json



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

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

  respond_to do |format|
    format.html # show.html.erb
    format.json { render :json => @product }
  end
end

#updateObject

PUT /admin/products/1 PUT /admin/products/1.json



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/adminpanel/products_controller.rb', line 62

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

  respond_to do |format|
    if @product.update_attributes(params[:product])
      format.html { redirect_to product_path(@product), :notice => 'Product was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render :action => "edit" }
      format.json { render :json => @product.errors, :status => :unprocessable_entity }
    end
  end
end