# Collection\_select to display 2 fields

**URL:** <https://www.ruby-forum.com/t/collection-select-to-display-2-fields/58995>\
**Category:** Rails\
**Created:** [April 27, 2006, 6:43pm UTC](https://www.ruby-forum.com/t/collection-select-to-display-2-fields/58995 "2006-04-27T18:43:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [April 27, 2006, 6:43pm UTC](https://www.ruby-forum.com/t/collection-select-to-display-2-fields/58995/1 "2006-04-27T18:43:09Z")

</div>

I’m trying to get a collection\_select generated Drop-down box to display  
two fields from a table (first name & last name); however, I am having  
trouble concatenating the symbols. It appears as though any code I put  
in the 5th argument for collection\_select is processed prior to  
executing the collection\_select method. The code executes successfully  
with 1 symbol in the 5th argument, but not when trying to concatenate 2.  
Any help is appreciated!

My code is below:

this works:  
\<%=collection\_select(:model\_name, :field\_name, @queryname, :id,  
:field\_name\_1)%\>

this doesn’t work:  
\<%=collection\_select(:model\_name, :field\_name, @queryname, :id,  
:field\_name\_1 & :field\_name\_2 )%\>

---

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [April 27, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/collection-select-to-display-2-fields/58995/2 "2006-04-27T19:51:44Z")

</div>

Ryan wrote:

> executing the collection\_select method. The code executes successfully  
> with 1 symbol in the 5th argument, but not when trying to concatenate 2.  
> Any help is appreciated!

Hey Ryan,

Yeah, that’s not gonna work. The helper is using object.send to call a  
method by using the symbol you pass it. I’m new to this, but try  
defining a new single method on your object which returns the  
concatenated string. Pass a symbol for that new method to  
collection\_select.

Can someone else comment on this approach?

Dan

---

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [April 27, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/collection-select-to-display-2-fields/58995/3 "2006-04-27T23:18:43Z")

</div>

I’ve figured out how to do this, but I’m not sure it’s 100%.

in the View:  
\<%=collection\_select(:model\_name, :field\_name, @queryname, :id,  
:translationClass)%\>

in the Model:  
composed\_of :translationClass,  
:mapping =\>  
[  
[:field\_name1, :field1],  
[:field\_name2, :field2],  
[‘nil’]  
]

The display in the Drop-down is the contents of field\_name1 &  
field\_name2, which is what I was trying to accomplish.

The [‘nil’] is the one I question. If I don’t insert a 3rd element in  
the Array, I get a message saying: wrong number of arguments (2 for 3)

So, I add it, and it works well. I have a hunch this is a type of  
workaround… but it does work.

---

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [April 28, 2006, 3:04pm UTC](https://www.ruby-forum.com/t/collection-select-to-display-2-fields/58995/4 "2006-04-28T15:04:09Z")

</div>

On Thu, 2006-04-27 at 18:43 +0200, Ryan wrote:

> this works:  
> \<%=collection\_select(:model\_name, :field\_name, @queryname, :id,  
> :field\_name\_1)%\>
> 
> this doesn’t work:  
> \<%=collection\_select(:model\_name, :field\_name, @queryname, :id,  
> :field\_name\_1 & :field\_name\_2 )%\>

* * *

see Aggregations which allows you to join to columns and use them at  
once.

Craig
