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.
0454b2d73007699b409d4d7a2bcf0b5f?d=identicon&s=25 Oom Tuinstoel (Guest)
on 2006-03-14 20: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?
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-03-15 15: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.
0454b2d73007699b409d4d7a2bcf0b5f?d=identicon&s=25 Oom Tuinstoel (Guest)
on 2006-03-16 20: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.