Class: Admin::Shop::ProductsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/admin/shop/products_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /admin/shop/products POST /admin/shop/products.js POST /admin/shop/products.json AJAX and HTML




65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/admin/shop/products_controller.rb', line 65

def create
  notice = 'Product created successfully.'
  error = 'Could not create Product.'
  
  @shop_product.attributes = params[:shop_product]
  
  begin
    @shop_product.save!
    
    respond_to do |format|
      format.html {
        redirect_to edit_admin_shop_product_path(@shop_product) if params[:continue]
        redirect_to admin_shop_products_path unless params[:continue]
      }
      format.js   { render :partial => '/admin/shop/products/index/product', :locals => { :excerpt => @shop_product } }
      format.json { render :json    => @shop_product.to_json }
    end
  rescue Exception => error
    respond_to do |format|
      format.html {
        flash[:error] = error
        render :new
      }
      format.js   { render :text => error, :status => :unprocessable_entity }
      format.json { render :json => { :error => error }, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /admin/shop/products/1 DELETE /admin/shop/products/1.js DELETE /admin/shop/products/1.xml DELETE /admin/shop/products/1.json AJAX and HTML




131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/controllers/admin/shop/products_controller.rb', line 131

def destroy
  notice = 'Product deleted successfully.'
  
  @shop_product.destroy
  
  respond_to do |format|
    format.html {
      redirect_to admin_shop_products_path 
    }
    format.js   { render  :text => notice, :status => :ok }
    format.json { render  :json => { :notice => notice }, :status => :ok }
  end
end

#indexObject

GET /admin/shop/products GET /admin/shop/products.js GET /admin/shop/products.json AJAX and HTML




21
22
23
24
25
26
27
28
29
# File 'app/controllers/admin/shop/products_controller.rb', line 21

def index
  @shop_categories = ShopCategory.all
  
  respond_to do |format|
    format.html { render :index }
    format.js   { render :partial => '/admin/shop/products/index/product', :collection => @shop_products }
    format.json { render :json    => @shop_products.to_json }
  end
end

#sortObject

PUT /admin/shop/products/sort PUT /admin/shop/products/sort.js PUT /admin/shop/products/sort.json AJAX and HTML




35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/admin/shop/products_controller.rb', line 35

def sort
  notice = 'Products successfully sorted.'
  error  = 'Could not sort Products.'
  
  begin
    ShopProduct.sort(params[:category_id], CGI::parse(params[:products])["category_#{params[:category_id]}_products[]"])
    
    respond_to do |format|
      format.html {
        redirect_to admin_shop_products_path
      }
      format.js   { render  :text => notice, :status => :ok }
      format.json { render  :json => { :notice => notice }, :status => :ok }
    end
  rescue
    respond_to do |format|
      format.html {
        flash[:error] = error
        redirect_to admin_shop_products_path
      }
      format.js   { render  :text => error, :status => :unprocessable_entity }
      format.json { render  :json => { :error => error }, :status => :unprocessable_entity }
    end
  end
end

#updateObject

PUT /admin/shop/products/1 PUT /admin/shop/products/1.js PUT /admin/shop/products/1.xml PUT /admin/shop/products/1.json AJAX and HTML




99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/controllers/admin/shop/products_controller.rb', line 99

def update
  notice = 'Product updated successfully.'
  error = 'Could not update Product.'
  
  begin
    @shop_product.update_attributes!(params[:shop_product])

    respond_to do |format|
      format.html {
        redirect_to edit_admin_shop_product_path(@shop_product) if params[:continue]
        redirect_to admin_shop_products_path unless params[:continue]
      }
      format.js   { render  :partial  => '/admin/shop/products/index/product', :locals => { :product => @shop_product } }
      format.json { render  :json     => @shop_product.to_json }
    end
  rescue Exception => error
    respond_to do |format|
      format.html {
        flash[:error] = error
        render :edit
      }
      format.js   { render  :text => error, :status => :unprocessable_entity }
      format.json { render  :json => { :error => error }, :status => :unprocessable_entity }
    end
  end
end