Sha256: bb65b668eeb9fa02719f90bed664e73df88e3baa9d7ba0b26fe693af92416af6

Contents?: true

Size: 1012 Bytes

Versions: 5

Compression:

Stored size: 1012 Bytes

Contents

class ProductsController < InheritedResources::Base

  unloadable

  def edit
    @product = Product.find_by_permalink(params['id']) || Product.find_by_id(params['id'])
    edit!
  end

  def update
    @product = Product.find_by_permalink(params['id']) || Product.find_by_id(params['id'])
    update!
  end

  def search
    # http://railscasts.com/episodes/120-thinking-sphinx with will_paginate
    # @products = Product.search(params[:q], :page => 1, :per_page => 5, :order => :name)

    @products = Product.where('name like ? or tags like ?', "%#{params['q']}%", "%#{params['q']}%").paginate(:per_page => 10, :page => params[:page])

    respond_to do |format|
      format.html { render :template => 'products/search/index' }
      format.xml  { render :xml => @products }
    end
  end
      
  def by_permalink
    if @product = Product.find_by_permalink(params['path'])
      render :template => 'products/show'
    else
      render :template => 'public/404.html', :status => '404'
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ecommerce-0.0.6 app/controllers/products_controller.rb
ecommerce-0.0.5 app/controllers/products_controller.rb
ecommerce-0.0.4 app/controllers/products_controller.rb
ecommerce-0.0.3 app/controllers/products_controller.rb
ecommerce-0.0.2 app/controllers/products_controller.rb