# Getting multiple select to work: options\_for\_select

**URL:** <https://www.ruby-forum.com/t/getting-multiple-select-to-work-options-for-select/126828>\
**Category:** Rails\
**Created:** [January 22, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/getting-multiple-select-to-work-options-for-select/126828 "2008-01-22T16:24:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![truchty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f475e1/32.png) [@truchty](https://www.ruby-forum.com/u/truchty)\
**Post date:** [January 22, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/getting-multiple-select-to-work-options-for-select/126828/1 "2008-01-22T16:24:26Z")

</div>

Hi,

\<%= select\_tag ‘image\_id’, options\_for\_select(Image.find(:all) {|  
an\_image| [an\_image.name, an\_image.id] }), :multiple =\> true %\>

- I am in a view, and I am trying to search the image table and make a  
multiple select box with each image’s name.
- Right now it is working, but I see this:

* * *

## #Image:0xklasjdka | #Image:0xklasb987 | #Image:0xkla9a8sd | #Image:0xklasasjd v

- The desired end result should look like this:

* * *

## top.jpg | back.jpg | left.jpg | upper.jpg v

Can anyone tell me why I am getting this object back like this, and  
how to fix it?

-truchty

( ps I am a rails n00b )

---

<div class="post-metadata">

**Author:** ![truchty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f475e1/32.png) [@truchty](https://www.ruby-forum.com/u/truchty)\
**Post date:** [January 22, 2008, 4:45pm UTC](https://www.ruby-forum.com/t/getting-multiple-select-to-work-options-for-select/126828/2 "2008-01-22T16:45:55Z")

</div>

Jerzy :

> \<%= select\_tag ‘image\_id’, options\_for\_select(Image.find(:all) {|  
> an\_image| [an\_image.name, an\_image.id] }), :multiple =\> true %\>

You’re attaching a block to Image.find that doesn’t need one.  
You should chain with a map method like that :

Image.find(:all).map { |an\_image| [an\_image.name, an\_image.id] }

You can use script/console to find the right expression and have  
instant feedback.

– Jean-François.
