Sha256: fc589ebcc8f3f59cbc088222c8ee2523164016dc4c970b978d459d1b9bd999ed
Contents?: true
Size: 1.89 KB
Versions: 3
Compression:
Stored size: 1.89 KB
Contents
module Tienda class ProductsController < Tienda::ApplicationController before_filter { @active_nav = :products } before_filter { params[:id] && @product = Tienda::Product.root.find(params[:id]) } def index @products = Tienda::Product.root.includes(:stock_level_adjustments, :default_image, :product_category, :variants).order(:name).group_by(&:product_category).sort_by { |cat,pro| cat.name } end def new @product = Tienda::Product.new end def create @product = Tienda::Product.new(safe_params) if @product.save redirect_to :products, flash: { notice: t('tienda.products.create_notice') } else render action: "new" end end def edit end def update if @product.update(safe_params) redirect_to [:edit, @product], flash: { notice: t('tienda.products.update_notice') } else render action: "edit" end end def destroy @product.destroy redirect_to :products, flash: { notice: t('tienda.products.destroy_notice')} end 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 private def safe_params params[:product].permit(:product_category_id, :name, :sku, :permalink, :description, :short_description, :weight, :price, :cost_price, :tax_rate_id, :stock_control, :default_image_file, :second_image_file, :third_image_file, :fourth_image_file, :fifth_image_file, :data_sheet_file, :active, :featured, :in_the_box, :product_attributes_array => [:key, :value, :searchable, :public]) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tienda-1.1.2 | app/controllers/tienda/products_controller.rb |
tienda-1.1.1 | app/controllers/tienda/products_controller.rb |
tienda-1.1.0 | app/controllers/tienda/products_controller.rb |