# How to get the multiple selected data from select\_tag

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-multiple-selected-data-from-select-tag/167682>\
**Category:** Rails\
**Created:** [May 11, 2009, 2:09pm UTC](https://www.ruby-forum.com/t/how-to-get-the-multiple-selected-data-from-select-tag/167682 "2009-05-11T14:09:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@nishi](https://www.ruby-forum.com/u/nishi)\
**Post date:** [May 11, 2009, 2:09pm UTC](https://www.ruby-forum.com/t/how-to-get-the-multiple-selected-data-from-select-tag/167682/1 "2009-05-11T14:09:52Z")

</div>

Im trying to get the multiple selected data from select\_tag., but its  
gives single data

I hv written.  
\<%=select\_tag( :cons\_attribute\_id,options\_from\_collection\_for\_select  
(Attribute.find\_all\_by\_attributetype(“cons”),  
“id”, “name”, 3),:multiple=\>true) %\>

I hv also written as:

\<%=select\_tag( :cons\_attribute\_id[],options\_from\_collection\_for\_select  
(Attribute.find\_all\_by\_attributetype(“cons”),  
“id”, “name”, 3),:multiple=\>true) %\>

but it gives error… such as method not defined

---

<div class="post-metadata">

**Author:** ![nishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@nishi](https://www.ruby-forum.com/u/nishi)\
**Post date:** [May 11, 2009, 2:14pm UTC](https://www.ruby-forum.com/t/how-to-get-the-multiple-selected-data-from-select-tag/167682/2 "2009-05-11T14:14:34Z")

</div>

On May 11, 12:18 pm, nishi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%=select\_tag( :cons\_attribute\_id[],options\_from\_collection\_for\_select  
> (Attribute.find\_all\_by\_attributetype(“cons”),  
> “id”, “name”, 3),:multiple=\>true) %\>
> 
> but it gives error… such as method not defined

when you write :foo[] ruby thinks that you want to call the [] method  
on the symbol :foo. You can be explicit that you want the symbol with  
content foo[] by doing :‘foo[]’  
In this case you could also just pass a string to select\_tag

Fred

---

<div class="post-metadata">

**Author:** ![nishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@nishi](https://www.ruby-forum.com/u/nishi)\
**Post date:** [May 11, 2009, 2:23pm UTC](https://www.ruby-forum.com/t/how-to-get-the-multiple-selected-data-from-select-tag/167682/3 "2009-05-11T14:23:22Z")

</div>

Hi Nishi,

Follow the  
blog[http://railsbuilder.blogspot.com/2009/05/multiple-select-option-in-rails.html](http://railsbuilder.blogspot.com/2009/05/multiple-select-option-in-rails.html)it  
may help you  
[http://railsbuilder.blogspot.com/2009/05/multiple-select-option-in-rails.html](http://railsbuilder.blogspot.com/2009/05/multiple-select-option-in-rails.html)

Thanks

---

<div class="post-metadata">

**Author:** ![nishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@nishi](https://www.ruby-forum.com/u/nishi)\
**Post date:** [May 12, 2009, 9:16am UTC](https://www.ruby-forum.com/t/how-to-get-the-multiple-selected-data-from-select-tag/167682/4 "2009-05-12T09:16:58Z")

</div>

Hi Fred,  
thx for ur resp.

but i hv one more ques.  
here we r using the

```
   options_from_collection_for_select

```

(Attribute.find\_all\_by\_attributetype(“cons”)

I need a solution where we will get the data from model not directly  
by “collection\_select”  
please give me sm idea, i need it as soon as possible.

---

<div class="post-metadata">

**Author:** ![nishi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ad7895/32.png) [@nishi](https://www.ruby-forum.com/u/nishi)\
**Post date:** [May 12, 2009, 7:57am UTC](https://www.ruby-forum.com/t/how-to-get-the-multiple-selected-data-from-select-tag/167682/5 "2009-05-12T07:57:35Z")

</div>

Thx Fred and Arun.

I got the solution,

\<%=select\_tag(“attribute\_id[]”,options\_from\_collection\_for\_select  
(Attribute.find\_all\_by\_attributetype(“cons”), “id”, “name”,  
3),:multiple=\>true) %\>
