Forum: Ruby on Rails Nubie: collection_select with two fields concatenated

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Oom Tuinstoel (Guest)
on 2006-03-14 21:17
I have a table with (among others) :prefix and :lastname

In my view in a collection_select I want to see "prefix lastname". I
have ab-so-lu-te-ly no idea how to do this. Can anybody show me?
Mark Reginald J. (Guest)
on 2006-03-15 16:51
(Received via mailing list)
Oom Tuinstoel wrote:
> I have a table with (among others) :prefix and :lastname
>
> In my view in a collection_select I want to see "prefix lastname". I
> have ab-so-lu-te-ly no idea how to do this. Can anybody show me?

Add a method to your model that returns "#{prefix} #{lastname}",
and use this as your text method in collection_select.

--
We develop, watch us RoR, in numbers too big to ignore.
Oom Tuinstoel (Guest)
on 2006-03-16 21:11
Thanks, Mark

I guess I'm still not used to the simplicity of rails...
This topic is locked and can not be replied to.