# Pull from two tables to populate a select

**URL:** <https://www.ruby-forum.com/t/pull-from-two-tables-to-populate-a-select/148436>\
**Category:** Rails\
**Created:** [September 12, 2008, 8:57pm UTC](https://www.ruby-forum.com/t/pull-from-two-tables-to-populate-a-select/148436 "2008-09-12T20:57:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 12, 2008, 8:57pm UTC](https://www.ruby-forum.com/t/pull-from-two-tables-to-populate-a-select/148436/1 "2008-09-12T20:57:05Z")

</div>

I need to populoate a drop-down with values from two tables. Currently I  
have this code which just pulls from one table:

\<%= select( “hotelmembership”, “hotel\_id”, Hotel.find( :all, :order=\>  
‘name’ ).collect {|h| [h.name, h.id]}, { :include\_blank =\> FALSE } ) %\>

Now I need to pull more data to add to this drop-down, but I am unsure  
of how to do this. Any suggestions?, Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 12, 2008, 9:06pm UTC](https://www.ruby-forum.com/t/pull-from-two-tables-to-populate-a-select/148436/2 "2008-09-12T21:06:07Z")

</div>

When you say you need more data–do you mean you’ve got another table  
w/rows that should get appended on to bottom of the list your present  
code produces? Or do you mean you want to e.g., concatenate some  
additional fields from another table onto each hotel’s name?

(Either way, consider moving your .find call to the controller &  
populating a variable to reference from your view, so as to keep the  
view nice & clean looking…)

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 12, 2008, 10:59pm UTC](https://www.ruby-forum.com/t/pull-from-two-tables-to-populate-a-select/148436/3 "2008-09-12T22:59:02Z")

</div>

Why don’t you collect all the data you need in an array or hash and  
once you are finished, populate the select?

On Sep 12, 8:57 pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 13, 2008, 11:43pm UTC](https://www.ruby-forum.com/t/pull-from-two-tables-to-populate-a-select/148436/4 "2008-09-13T23:43:14Z")

</div>

I have the same question as the other two, what additional information  
are you trying to add to this drop-down?

On Sep 12, 1:57 pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
