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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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...)
-----Original Message-----
From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
[mailto:rubyonrails-talk@googlegroups.com] On Behalf Of Shandy Nantz
Sent: Friday, September 12, 2008 11:57 AM
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: [Rails] Pull from two tables to populate a select
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---