options_from_collection_for_select with complex name

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?



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 http://agileconsultingllc.com

Thanks Rob! Worked great!