# Paginate! passing params\[\] for conditions for DB search

**URL:** <https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110>\
**Category:** Rails\
**Created:** [December 12, 2006, 6:52am UTC](https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110 "2006-12-12T06:52:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![john-anes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@john-anes](https://www.ruby-forum.com/u/john-anes)\
**Post date:** [December 12, 2006, 6:52am UTC](https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110/1 "2006-12-12T06:52:00Z")

</div>

Hey guys,

I have stuck on pagination by passing values from a text\_field for  
searching a db, It works on the first page and it throws an SQL error  
while clicking the second page. Below is my code, guys definetly help  
needed, thanks in advance.

# i pass search params from the text\_field in .rhtml

conditions = @params[‘search’].to\_s.split(’ ‘).collect {|query\_search|  
“requirements.position\_title LIKE ‘%#{query\_search}%’”}.join(’ OR ')

requirement = Requirement.find\_all  
@requirement\_pages, @requirements = paginate :requirements, :per\_page =\>  
5, :order =\> ‘opening\_date DESC’, :conditions =\> conditions

# error i get is about count(\*) which i dont use anywhere in the code. and The db config of mine is MySQL server 5.0

Mysql::Error: #42000You have an error in your SQL syntax; check the  
manual that corresponds to your MySQL server version for the right  
syntax to use near ‘)’ at line 1: SELECT count(\*) AS count\_all FROM  
requirements WHERE ()

regards  
john aneston

---

<div class="post-metadata">

**Author:** ![john-anes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@john-anes](https://www.ruby-forum.com/u/john-anes)\
**Post date:** [December 12, 2006, 7:21am UTC](https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110/2 "2006-12-12T07:21:27Z")

</div>

> syntax to use near ‘)’ at line 1: SELECT count(\*) AS count\_all FROM  
> requirements WHERE ()

Looks like on page 2, @params[‘search’] doesn’t contain any spaces so  
there’s nothing to split, collect, or join so ‘conditions’ is nil  
resulting in “WHERE ()” which is invalid.

Why @params[‘search’] instead of params[:search]?

Also, why are you finding all the requirements right before paginating?  
Seems like a redundant effort?

Check your logs to see what rails sees in it’s params when you hit page  
two…

-philip

---

<div class="post-metadata">

**Author:** ![john-anes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@john-anes](https://www.ruby-forum.com/u/john-anes)\
**Post date:** [December 12, 2006, 7:51am UTC](https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110/3 "2006-12-12T07:51:46Z")

</div>

Philip H. wrote:

> > syntax to use near ‘)’ at line 1: SELECT count(\*) AS count\_all FROM  
> > requirements WHERE ()
> 
> Looks like on page 2, @params[‘search’] doesn’t contain any spaces so  
> there’s nothing to split, collect, or join so ‘conditions’ is nil  
> resulting in “WHERE ()” which is invalid.
> 
> Why @params[‘search’] instead of params[:search]?
> 
> Also, why are you finding all the requirements right before paginating?  
> Seems like a redundant effort?
> 
> Check your logs to see what rails sees in it’s params when you hit page  
> two…
> 
> -philip

ok i got that Philip,  
thanks buddy… i have passed the parameter again from the .rhtml on the  
pagination link it works fine now. And i will check about the redundancy  
too which you are saying. Now i ubderstand much about it.  
thanks once again.  
regards  
john aneston

---

<div class="post-metadata">

**Author:** ![john-anes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@john-anes](https://www.ruby-forum.com/u/john-anes)\
**Post date:** [December 12, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110/4 "2006-12-12T13:36:39Z")

</div>

i had similiar problem and mine may be different. when i was running  
into errors when trying to click on page 2 of my paginate object, it was  
due to params being passed as null and not being carried offer. this was  
easily solved by keeping track of my params variables via session  
cookies.

---

<div class="post-metadata">

**Author:** ![john-anes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@john-anes](https://www.ruby-forum.com/u/john-anes)\
**Post date:** [December 12, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110/5 "2006-12-12T14:18:01Z")

</div>

Hi

Is there a way to have ‘rake stats’ read my specs as tests and log my  
specs’ lines of code accordingly?

Thanks in advance.  
Gustav P.

---

<div class="post-metadata">

**Author:** ![john-anes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@john-anes](https://www.ruby-forum.com/u/john-anes)\
**Post date:** [December 13, 2006, 12:12pm UTC](https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110/6 "2006-12-13T12:12:05Z")

</div>

> Is there a way to have ‘rake stats’ read my specs as tests and log my  
> specs’ lines of code accordingly?

Try:

> rake spec:statsetup

That should setup stats to use rspec.

hth

–  
Richard L.  
Head of Agile Development, CitySafe

[http://citysafe.org](http://citysafe.org) … CitySafe  
[http://thatsprogress.com](http://thatsprogress.com) … The Fitness Community (soon)  
[http://livsey.org](http://livsey.org) … Blog : Musings of a Rails Developer

---

<div class="post-metadata">

**Author:** ![john-anes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@john-anes](https://www.ruby-forum.com/u/john-anes)\
**Post date:** [December 13, 2006, 1:30pm UTC](https://www.ruby-forum.com/t/paginate-passing-params-for-conditions-for-db-search/79110/7 "2006-12-13T13:30:46Z")

</div>

i know i had some issues passing parameters with the pagination links,  
don’t know if this is what you’re dealing with; but go for

\<%= pagination\_links(@requirement\_pages), :params =\> {:search =\>  
params[:search]} %\>

and when u reach the second page via this link, you won’t get the error,  
as the parameters have been passed…
