Sha256: ba24f588eb4c40d4b2b1d97d6e60ca0ded07d2778605d27bd78f48e232fdad8b

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 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, :tax_rate, :stock, :default_image_file, :data_sheet_file, :active, :featured, :in_the_box)
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shoppe-0.0.7 app/controllers/shoppe/products_controller.rb
shoppe-0.0.6 app/controllers/shoppe/products_controller.rb
shoppe-0.0.5 app/controllers/shoppe/products_controller.rb