Hi guys!
I am using will_paginate in my rails application.
I want to merge these 2 lines in one:
@cat_products1 = Product.find(:all, :conditions => {:category_id
=> params[:id]})
@cat_products2 = Product.paginate(:per_page => 5, :page => params
[:page],
:conditions => [‘title like ?’ , “%#
{params[:search]}%”],
:order => ‘title’)
I want to paginate using the condition category_id=>params[:id]
Any sollutions???
Thank u!
Kostas L.
2009/9/19 Kostas L. [email protected]:
{params[:search]}%"],
                :order => ‘title’)
I want to paginate using the condition category_id=>params[:id]
Any sollutions???
Can’t you just include the category_id in the conditions for the
paginate call? Or am I missing something?
Colin
I do this but i get a systax error. Maybe i’m doing something wrong. I
wrote this:
@cat_products = Product.paginate(:per_page => 5, :page => params
[:page],
:conditions => {[‘title like ?’ , “%#
{params[:search]}%”], :category_id => params[:id]},
:order => ‘title’)
Any ideas???
Thanx
@cat_products = Product.paginate(:per_page => 5, :page => params
[:page],
:conditions => {[‘title like ?’ , “%#
{params[:search]}%”], :category_id => params[:id]},
:order => ‘title’)
You’re mixing 2 styles of defining conditions here. You should be
able to do this:
Product.paginate(:per_page => 5,
:page => params[:page],
:conditions => [“title LIKE ?”, “%#{params
[:search]}%”, params[:id]],
:order => ‘title’)
The :conditions array accepts either a string with ? placeholders
followed by parameters in a list:
["title = ? AND name = ?, arg1, arg2]
or a string with symbol placeholders followed by a hash:
[“title = :title AND name = :name”, {:title => “foo”, :name => “bar”}]
Hope that explains it and helps.
Steve
2009/9/20 Stephen B. [email protected]:
            :page => params[:page],
            :conditions => [“title LIKE ?”, “%#{params
[:search]}%”, params[:id]],
Should that be :conditions => [“title LIKE ? AND category_id = ?”,
"%#{params
[:search]}%", params[:id]],
Colin