Class: Tienda::ProductsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Tienda::ProductsController
- Defined in:
- app/controllers/tienda/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
19 20 21 22 23 24 25 26 |
# File 'app/controllers/tienda/products_controller.rb', line 19 def create @product = Tienda::Product.new(safe_params) if @product.save redirect_to :products, flash: { notice: t('tienda.products.create_notice') } else render :new end end |
#destroy ⇒ Object
39 40 41 42 |
# File 'app/controllers/tienda/products_controller.rb', line 39 def destroy @product.destroy redirect_to :products, flash: { notice: t('tienda.products.destroy_notice')} end |
#edit ⇒ Object
28 29 |
# File 'app/controllers/tienda/products_controller.rb', line 28 def edit end |
#import ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/tienda/products_controller.rb', line 44 def import if request.post? if params[:import].nil? redirect_to import_products_path, flash: { alert: I18n.t('tienda.imports.errors.no_file') } else Tienda::Product.import(params[:import][:import_file]) redirect_to products_path, flash: { notice: I18n.t("tienda.products.imports.success") } end end end |
#index ⇒ Object
7 8 9 10 11 12 13 |
# File 'app/controllers/tienda/products_controller.rb', line 7 def index if params[:filter].blank? @products = Tienda::Product.root.includes(:stock_level_adjustments, :product_images, :product_category, :variants).order(:name).group_by(&:product_category).sort_by { |cat, pro| cat.name } else @products = Tienda::Product.root.send(params[:filter]).includes(:stock_level_adjustments, :product_images, :product_category, :variants).order(:name).group_by(&:product_category).sort_by { |cat, pro| cat.name } end end |
#new ⇒ Object
15 16 17 |
# File 'app/controllers/tienda/products_controller.rb', line 15 def new @product = Tienda::Product.new end |
#update ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/controllers/tienda/products_controller.rb', line 31 def update if @product.update(safe_params) redirect_to [:edit, @product], flash: { notice: t('tienda.products.update_notice') } else render :edit end end |