# Partial matches with find\_by

**URL:** <https://www.ruby-forum.com/t/partial-matches-with-find-by/95801>\
**Category:** Rails\
**Created:** [June 14, 2006, 2:27am UTC](https://www.ruby-forum.com/t/partial-matches-with-find-by/95801 "2006-06-14T02:27:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasbur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jasbur](https://www.ruby-forum.com/u/jasbur)\
**Post date:** [June 14, 2006, 2:27am UTC](https://www.ruby-forum.com/t/partial-matches-with-find-by/95801/1 "2006-06-14T02:27:10Z")

</div>

I have a form passing a parameter to a “show\_search” action. Everything  
goes fine, as long as i search for the exact title of the post. How do I  
do a partial or “wild card” search? Code below:

def show\_search  
@posts = Post.find\_all\_by\_title(params[:title])  
end

---

<div class="post-metadata">

**Author:** ![jasbur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jasbur](https://www.ruby-forum.com/u/jasbur)\
**Post date:** [June 14, 2006, 3:51am UTC](https://www.ruby-forum.com/t/partial-matches-with-find-by/95801/2 "2006-06-14T03:51:21Z")

</div>

Jasbur wrote:

> I have a form passing a parameter to a “show\_search” action. Everything  
> goes fine, as long as i search for the exact title of the post. How do I  
> do a partial or “wild card” search? Code below:
> 
> def show\_search  
> @posts = Post.find\_all\_by\_title(params[:title])  
> end

Whilst I am far from an expert I think you need to use find options or  
find\_by\_Sql

search\_string = ‘’%’ + params[:title] + ‘%’’  
Post.find(:all,  
:conditions =\> [“title like ?”, search\_string]  
:order =\> ‘title’  
)
