# Searching on two table fields

**URL:** <https://www.ruby-forum.com/t/searching-on-two-table-fields/150810>\
**Category:** Rails\
**Created:** [October 13, 2008, 5:01pm UTC](https://www.ruby-forum.com/t/searching-on-two-table-fields/150810 "2008-10-13T17:01:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@martinevans](https://www.ruby-forum.com/u/martinevans)\
**Post date:** [October 13, 2008, 5:01pm UTC](https://www.ruby-forum.com/t/searching-on-two-table-fields/150810/1 "2008-10-13T17:01:08Z")

</div>

i have a recipe table  
id  
recipe\_title  
diet\_id  
meal\_id

I have set up the associations and can create, edit and delete recipes  
no problem.  
I have set up navigation with a list of diets for example low carb,  
high fibre which when clicked shows all the recipes with that type of  
diet. I then display a list of meals, breakast, lunch, dinner snack etc.  
I’m unsure how to do the select in the controller/model so that only  
breakfast for that diet are shown  
Can anyone give me some pointers as to how to proceed.  
regards  
Martin

---

<div class="post-metadata">

**Author:** ![martinevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@martinevans](https://www.ruby-forum.com/u/martinevans)\
**Post date:** [October 13, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/searching-on-two-table-fields/150810/2 "2008-10-13T18:05:07Z")

</div>

I believe e.g., Recipe.find\_by\_diet\_id\_and\_meal\_id(12, 34) should work.

---

<div class="post-metadata">

**Author:** ![martinevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@martinevans](https://www.ruby-forum.com/u/martinevans)\
**Post date:** [October 13, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/searching-on-two-table-fields/150810/3 "2008-10-13T18:10:17Z")

</div>

Roy P. wrote:

> I believe e.g., Recipe.find\_by\_diet\_id\_and\_meal\_id(12, 34) should work.

Thanks but how do I pass the parameters in link\_to

regards  
Martin

---

<div class="post-metadata">

**Author:** ![martinevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@martinevans](https://www.ruby-forum.com/u/martinevans)\
**Post date:** [October 13, 2008, 8:41pm UTC](https://www.ruby-forum.com/t/searching-on-two-table-fields/150810/4 "2008-10-13T20:41:15Z")

</div>

Roy P. wrote:

> link\_to “click me” :controller =\> ‘some\_controller’, :action =\>  
> ‘my\_action’, :this\_recipe\_id =\> @recipe, :this\_meal\_id =\> @meal
> 
> But depending on where you put that link there are probably shorthands  
> you can use.
> 
> HTH,
> 
> -Roy

thanks Roy, that’s been a great help

---

<div class="post-metadata">

**Author:** ![martinevans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f475e1/32.png) [@martinevans](https://www.ruby-forum.com/u/martinevans)\
**Post date:** [October 13, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/searching-on-two-table-fields/150810/5 "2008-10-13T18:38:38Z")

</div>

link\_to “click me” :controller =\> ‘some\_controller’, :action =\>  
‘my\_action’, :this\_recipe\_id =\> @recipe, :this\_meal\_id =\> @meal

But depending on where you put that link there are probably shorthands  
you can use.

HTH,

-Roy
