jim dandy
2006-Jul-30 02:19 UTC
[Rails] options_from_collection_for_select & multiple columns
I have a table with first_name and last_name, and wan''t to populate a drop-down with the id and the person''s name consisting of the first and last names concatenated together. Can''t figure out how to tell options_from_collection_for_select to do that. Any ideas? I basically need to do something like: <%= options_from_collection_for_select @media_creators, "id", "last_name + '' '' + first_name", @media.media_creator_id %> media belongs_to media_creator media_creator has_many media Thanks! -- Posted via http://www.ruby-forum.com/.
Jeff Dean
2006-Jul-30 02:28 UTC
[Rails] options_from_collection_for_select & multiple columns
Create a new attribute on the model, then use that model - so in media creator model: def full_name self.first_name+'' ''+self.last_name end then on the select: <%= options_from_collection_for_select @media_creators, "id", "full_name", @media.media_creator_id %> www.jefdean.com jeff@jefdean.com 917 414 7801 -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of jim dandy Sent: Saturday, July 29, 2006 10:20 PM To: rails@lists.rubyonrails.org Subject: [Rails] options_from_collection_for_select & multiple columns I have a table with first_name and last_name, and wan''t to populate a drop-down with the id and the person''s name consisting of the first and last names concatenated together. Can''t figure out how to tell options_from_collection_for_select to do that. Any ideas? I basically need to do something like: <%= options_from_collection_for_select @media_creators, "id", "last_name + '' '' + first_name", @media.media_creator_id %> media belongs_to media_creator media_creator has_many media Thanks! -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
jim dandy
2006-Jul-30 03:36 UTC
[Rails] Re: RE: options_from_collection_for_select & multiple column
Jeff Dean wrote:> Create a new attribute on the model, then use that model - so in media > creator model: > > def full_name > self.first_name+'' ''+self.last_name > end > > then on the select: > > <%= options_from_collection_for_select @media_creators, "id", > "full_name", > @media.media_creator_id %> > > www.jefdean.com > jeff@jefdean.com > 917 414 7801worked like a charm! thanks for the advice. it''s taking a while to get used to working with the MVC framework. still thinking in asp/cold fusion ways. -- Posted via http://www.ruby-forum.com/.