All pastes #568784 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-15 19:39 UTC
rendered paste body
class AdminProductController < ApplicationController

	before_filter :authorize
	layout "admin"

	def parent_category_changed
		render :partial => "categories", :locals => {:parent_category_id => @params[:id]}
	end
	
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
  	@categories = Category.find(:all)
	@parent_categories = ParentCategory.find(:all)
	@product_pages, @products = paginate :products, :per_page => 10
  end
  
  def list_parent_category
  	@categories = Category.find(:all)
	@parent_categories = ParentCategory.find(:all)
	@products_ = Product.find(:all, :conditions => ["parent_category_id =?", params[:id]])
	#@product_pages, @products = paginate :products, :per_page => 10
  end

  def list_category
  	@categories = Category.find(:all)
	@parent_categories = ParentCategory.find(:all)
	@products_ = Product.find(:all, :conditions => ["category_id =?", params[:id]])
	#@product_pages, @products = paginate :products, :per_page => 10
  end
  
  def show
    @product = Product.find(params[:id])
  end

  def new
  	@parent_categories = ParentCategory.find(:all)
	#@categories = Category.find_by_parent_category_name('Calculatoare')
	@categories = Category.find_all
    @product = Product.new
  end

  def create
    @product = Product.new(params[:product])
    if @product.save
      flash[:notice] = 'Product was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
  	@parent_categories = ParentCategory.find(:all)
	@categories = Category.find_all
    @product = Product.find(params[:id])
  end

  def update
    @product = Product.find(params[:id])
    if @product.update_attributes(params[:product])
      flash[:notice] = 'Product was successfully updated.'
      redirect_to :action => 'show', :id => @product
    else
      render :action => 'edit'
    end
  end

  def destroy
    Product.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end