# Paginate conditions

**URL:** <https://www.ruby-forum.com/t/paginate-conditions/144773>\
**Category:** Rails\
**Created:** [August 1, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/paginate-conditions/144773 "2008-08-01T22:37:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 1, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/paginate-conditions/144773/1 "2008-08-01T22:37:53Z")

</div>

paginate :per\_page =\> 15, :page =\> page,  
:conditions =\> [‘tags like ?’, “%#{search}%”], :order =\> ‘created\_at  
DESC’

Hi, just wondering how I would change the conditions to include an extra  
like?

I want to do:  
‘tags AND body like ?’

Not sure what’s the proper syntax for this,

Thanks!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 1, 2008, 10:47pm UTC](https://www.ruby-forum.com/t/paginate-conditions/144773/2 "2008-08-01T22:47:22Z")

</div>

On Aug 1, 2008, at 1:37 PM, Justin To wrote:

> ‘tags AND body like ?’
> 
> Not sure what’s the proper syntax for this,

That part is straight SQL (with some nice substitutions) so you’d want:

:conditions =\> [‘tags LIKE ? AND body LIKE ?’, “%#{search}%”,  
“%#{search}%”]

that will return results where both tag and body are like your search.

-philip

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 1, 2008, 11:11pm UTC](https://www.ruby-forum.com/t/paginate-conditions/144773/3 "2008-08-01T23:11:47Z")

</div>

Super, thanks! Is there such an operator as OR?

Thanks!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 2, 2008, 12:15am UTC](https://www.ruby-forum.com/t/paginate-conditions/144773/4 "2008-08-02T00:15:17Z")

</div>

Philip H. wrote:

> > Super, thanks! Is there such an operator as OR?
> 
> Yep. OR 🙂
> 
> No idea what your level of SQL knowledge is and I don’t mean to give  
> offense, but you may find this helpful:
> 
> [SQL Tutorial](http://w3schools.com/sql/default.asp)
> 
> -philip

Ha ha, thanks Philip. I’ve read that article before. The problem is, I  
haven’t worked very much with SQL at all before. =) Thanks!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 1, 2008, 11:43pm UTC](https://www.ruby-forum.com/t/paginate-conditions/144773/5 "2008-08-01T23:43:05Z")

</div>

> Super, thanks! Is there such an operator as OR?

Yep. OR 🙂

No idea what your level of SQL knowledge is and I don’t mean to give  
offense, but you may find this helpful:

> **[SQL Tutorial](https://www.w3schools.com/sql/default.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

-philip
