Forum: Ruby on Rails options_from_collection_for_select with complex name

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0cfa43ade56eed9cabe9fa21d85dd805?d=identicon&s=25 gabordemeter (Guest)
on 2007-06-12 22:49
(Received via mailing list)
Hi everyone,

I just came across this problem and don't know how to solve it. I have
a select list:

<%= select_tag :tech_lead, options_from_collection_for_select
(@employees, "id", "first_name", @project.tech_lead.to_i), {:class =>
"text_field_project"} %>

As you will notice, I have an @employees collection passed to the
"options_from_collection_for_select" which contains a "first_name" and
"last_name" attributes.

Right now my select list properly display the first name of all
employees (as you can see in the code above), however, I'd like to
make it display "first_name space last_name" (like "John Smith").

How can I make this happen in the above code?


Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-06-12 23:25
(Received via mailing list)
On Jun 12, 2007, at 4:48 PM, gabordemeter wrote:

> Thanks,
> Gabor

Add this to your model and tell the options_... call to use
'full_name' rather than 'first_name'

def full_name
   [ self.first_name, self.last_name ].compact.join(' ')

Or perhaps

def full_name
   "#{self.first_name} #{self.last_name}".strip


Rob Biedenharn
0cfa43ade56eed9cabe9fa21d85dd805?d=identicon&s=25 gabordemeter (Guest)
on 2007-06-13 01:40
(Received via mailing list)
Thanks Rob! Worked great!

On Jun 12, 2:24 pm, Rob Biedenharn <>
This topic is locked and can not be replied to.