Class: Shoppe::ProductsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Shoppe::ProductsController
- Defined in:
- app/controllers/shoppe/products_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #stock_levels ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/controllers/shoppe/products_controller.rb', line 14 def create @product = Shoppe::Product.new(safe_params) if @product.save redirect_to :products, :flash => {:notice => "Product has been created successfully"} else render :action => "new" end end |
#destroy ⇒ Object
34 35 36 37 |
# File 'app/controllers/shoppe/products_controller.rb', line 34 def destroy @product.destroy redirect_to :products, :flash => {:notice => "Product has been removed successfully"} end |
#edit ⇒ Object
23 24 |
# File 'app/controllers/shoppe/products_controller.rb', line 23 def edit end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/shoppe/products_controller.rb', line 6 def index @products = Shoppe::Product.includes(:stock_level_adjustments, :default_image, :product_category).order(:title).group_by(&:product_category).sort_by { |cat,pro| cat.name } end |
#new ⇒ Object
10 11 12 |
# File 'app/controllers/shoppe/products_controller.rb', line 10 def new @product = Shoppe::Product.new end |
#stock_levels ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/shoppe/products_controller.rb', line 39 def stock_levels @stock_level_adjustments = @product.stock_level_adjustments.ordered.page(params[:page]) if request.post? @new_sla = @product.stock_level_adjustments.build(params[:stock_level_adjustment].permit(:description, :adjustment)) if @new_sla.save redirect_to [:stock_levels, @product], :notice => "Stock level adjustment has been recorded" else flash.now[:alert] = @new_sla.errors..to_sentence end else @new_sla = @product.stock_level_adjustments.build end end |
#update ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/controllers/shoppe/products_controller.rb', line 26 def update if @product.update(safe_params) redirect_to [:edit, @product], :flash => {:notice => "Product has been updated successfully"} else render :action => "edit" end end |