# Table search question

**URL:** <https://www.ruby-forum.com/t/table-search-question/119339>\
**Category:** Rails\
**Created:** [November 6, 2007, 5:30am UTC](https://www.ruby-forum.com/t/table-search-question/119339 "2007-11-06T05:30:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 6, 2007, 5:30am UTC](https://www.ruby-forum.com/t/table-search-question/119339/1 "2007-11-06T05:30:13Z")

</div>

i have a procedures table and a procedure model - it contain procedure  
descriptions as well as procedure codes.  
I would like the user to enter a procedure description (eye surgery)  
into a test field and then i would like to return the corresponding  
procedure code. Does this code look correct? the  
‘find\_by\_procedure\_code’ is what confuses me.

@procedure = Procedure.find\_by\_procedure\_code(params[:procedure]  
[:code])

---

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 6, 2007, 5:54pm UTC](https://www.ruby-forum.com/t/table-search-question/119339/2 "2007-11-06T17:54:05Z")

</div>

On 11/5/07, agilehack [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [:code])  
> This is the same as:

Procedure.find(:first, :conditions =\> ‘procedure\_code=?’,  
params[:procedure][:code])

But if you have a description and want to find the corresponding code,  
this is not the right query; it’s finding a procedure given it’s code.

If the description field is called “description” then this:

procedure = Procedure.find\_by\_description(“eye surgery”)

would return the first Procedure whose description is “eye surgery”,  
or nil if there is no such procedure. Assuming you found a row,

code = procedure.code

would give you the code for eye surgery.

HTH
