# Getting values from multiple select

**URL:** <https://www.ruby-forum.com/t/getting-values-from-multiple-select/169030>\
**Category:** Rails\
**Created:** [May 28, 2009, 4:20pm UTC](https://www.ruby-forum.com/t/getting-values-from-multiple-select/169030 "2009-05-28T16:20:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 28, 2009, 4:20pm UTC](https://www.ruby-forum.com/t/getting-values-from-multiple-select/169030/1 "2009-05-28T16:20:17Z")

</div>

I try to get the values from a multiple select without luck. This is my  
select:

\<%= select “product”, “items”, @options, {}, { :multiple =\> true } %\>

If I add it directly to a column in the db I get:

* * *

- !binary |  
xGdn

What should I do with this?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 28, 2009, 4:38pm UTC](https://www.ruby-forum.com/t/getting-values-from-multiple-select/169030/2 "2009-05-28T16:38:39Z")

</div>

Is this in a form\_for? if not you should use select\_tag

[http://apidock.com/rails/ActionView/Helpers/FormTagHelper/select\_tag](http://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag)

What do you have in @options?

This is the select method  
select(object, method, choices, options = {}, html\_options = {})

Examples here  
[http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select](http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select)

To debug these issues you should have a look at the compiled source  
with view source in the browser and see what you got.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 28, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/getting-values-from-multiple-select/169030/3 "2009-05-28T20:46:41Z")

</div>

Freddy A. wrote:

> Is this in a form\_for? if not you should use select\_tag
> 
> [select\_tag (ActionView::Helpers::FormTagHelper) - APIdock](http://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag)
> 
> What do you have in @options?
> 
> This is the select method  
> select(object, method, choices, options = {}, html\_options = {})
> 
> Examples here  
> [select (ActionView::Helpers::FormOptionsHelper) - APIdock](http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select)
> 
> To debug these issues you should have a look at the compiled source  
> with view source in the browser and see what you got.

That helped. But I only get the first value. Even if I use “items[]”.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 28, 2009, 9:05pm UTC](https://www.ruby-forum.com/t/getting-values-from-multiple-select/169030/4 "2009-05-28T21:05:56Z")

</div>

Freddy A. wrote:

> Is this in a form\_for? if not you should use select\_tag
> 
> [select\_tag (ActionView::Helpers::FormTagHelper) - APIdock](http://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag)
> 
> What do you have in @options?
> 
> This is the select method  
> select(object, method, choices, options = {}, html\_options = {})
> 
> Examples here  
> [select (ActionView::Helpers::FormOptionsHelper) - APIdock](http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select)
> 
> To debug these issues you should have a look at the compiled source  
> with view source in the browser and see what you got.

I’m back to start. I got

* * *

- 
  - !binary |  
xGdn

This tells me that it also worked with “select”.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 28, 2009, 9:15pm UTC](https://www.ruby-forum.com/t/getting-values-from-multiple-select/169030/5 "2009-05-28T21:15:27Z")

</div>

PÃ¥l BergstrÃ¶m wrote:

> Freddy A. wrote:

> * * *
> 
> - 
> - !binary |  
> xGdn
> 
> This tells me that it also worked with “select”.

Maybe better to ask; is anyone using multiple select in Rails? How does  
it work?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [May 30, 2009, 12:11pm UTC](https://www.ruby-forum.com/t/getting-values-from-multiple-select/169030/6 "2009-05-30T12:11:54Z")

</div>

On May 28, 7:46 pm, Pål Bergström [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > To debug these issues you should have a look at the compiled source  
> > with view source in the browser and see what you got.
> 
> That helped. But I only get the first value. Even if I use “items[]”.

Where is it going wrong ? Does your controller only ever say the first  
value or do your logs show that the controller receives multiple  
values. Look at the html source: does the name of the select tag end  
with [] ?

Fred
