Class: KktShoppe::ProductsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- KktShoppe::ProductsController
- Defined in:
- app/controllers/kkt_shoppe/products_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #import ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/controllers/kkt_shoppe/products_controller.rb', line 15 def create @product = KktShoppe::Product.new(safe_params) if @product.save redirect_to :products, :flash => {:notice => t('kkt_shoppe.products.create_notice') } else render :action => "new" end end |
#destroy ⇒ Object
35 36 37 38 |
# File 'app/controllers/kkt_shoppe/products_controller.rb', line 35 def destroy @product.destroy redirect_to :products, :flash => {:notice => t('kkt_shoppe.products.destroy_notice')} end |
#edit ⇒ Object
24 25 |
# File 'app/controllers/kkt_shoppe/products_controller.rb', line 24 def edit end |
#import ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/kkt_shoppe/products_controller.rb', line 40 def import if request.post? if params[:import].nil? redirect_to import_products_path, :flash => {:alert => I18n.t('kkt_shoppe.imports.errors.no_file')} else KktShoppe::Product.import(params[:import][:import_file]) redirect_to products_path, :flash => {:notice => I18n.t("kkt_shoppe.products.imports.success")} end end end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/kkt_shoppe/products_controller.rb', line 7 def index @products = KktShoppe::Product.root.includes(:translations, :stock_level_adjustments, :product_categories, :variants).order(:name).group_by(&:product_category).sort_by { |cat,pro| cat.name } end |
#new ⇒ Object
11 12 13 |
# File 'app/controllers/kkt_shoppe/products_controller.rb', line 11 def new @product = KktShoppe::Product.new end |
#update ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/controllers/kkt_shoppe/products_controller.rb', line 27 def update if @product.update(safe_params) redirect_to [:edit, @product], :flash => {:notice => t('kkt_shoppe.products.update_notice') } else render :action => "edit" end end |