Class: Admin::ProductsController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject

override the destory method to set deleted_at value instead of actually deleting the product.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/admin/products_controller.rb', line 35

def destroy
  @product = Product.find_by_permalink(params[:id])
  @product.deleted_at = Time.now()
  
  @product.variants.each do |v|   
    v.deleted_at = Time.now()
    v.save
  end
  
  if @product.save
    flash[:notice] = "Product has been deleted"
  else
    flash[:notice] = "Product could not be deleted"
  end
  
  redirect_to collection_url
end