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? Thanks, Gabor --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jun-12 21:24 UTC
Re: options_from_collection_for_select with complex name
On Jun 12, 2007, at 4:48 PM, gabordemeter wrote:> > 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? > > > Thanks, > > GaborAdd 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('' '') end Or perhaps def full_name "#{self.first_name} #{self.last_name}".strip end -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gabordemeter
2007-Jun-12 23:40 UTC
Re: options_from_collection_for_select with complex name
Thanks Rob! Worked great! On Jun 12, 2:24 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Jun 12, 2007, at 4:48 PM, gabordemeter wrote: > > > > > > > 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? > > > 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('' '') > end > > Or perhaps > > def full_name > "#{self.first_name} #{self.last_name}".strip > end > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---