Sha256: bd243fe463554db4e7fb46b038c1a43f731b48a1e913a024c697b2b2f52dccbe

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

class Shoppe::ProductsController < Shoppe::ApplicationController
  
  before_filter { @active_nav = :products }
  before_filter { params[:id] && @product = Shoppe::Product.find(params[:id]) }
  
  def index
    @products = Shoppe::Product.includes(:default_image, :product_category).order(:title).group_by(&:product_category).sort_by { |cat,pro| cat.name }
  end
  
  def new
    @product = Shoppe::Product.new
  end
  
  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
  
  def edit
  end
  
  def update
    if @product.update(safe_params)
      redirect_to [:edit, @product], :flash => {:notice => "Product has been updated successfully"}
    else
      render :action => "edit"
    end
  end
  
  def destroy
    @product.destroy
    redirect_to :products, :flash => {:notice => "Product has been removed successfully"}
  end
  
  private
  
  def safe_params
    params[:product].permit(:product_category_id, :title, :sku, :permalink, :description, :short_description, :weight, :price, :cost_price, :tax_rate, :stock_control, :stock, :default_image_file, :data_sheet_file, :active, :featured, :in_the_box, :product_attributes_array => [:key, :value, :searchable, :public])
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shoppe-0.0.9 app/controllers/shoppe/products_controller.rb
shoppe-0.0.8 app/controllers/shoppe/products_controller.rb