Forum: Ruby on Rails how to get the multiple selected data from select_tag.

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.
6bf5a62e064a8419f8d9930573a315de?d=identicon&s=25 nishi (Guest)
on 2009-05-11 14:09
(Received via mailing list)
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-11 14:14
(Received via mailing list)
On May 11, 12:18 pm, nishi <n.mridut...@gmail.com> 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
375d7ac426d619ce9c2add272a51d5bf?d=identicon&s=25 Arun Kumar (jakthegr8)
on 2009-05-11 14:23
(Received via mailing list)
6bf5a62e064a8419f8d9930573a315de?d=identicon&s=25 nishi (Guest)
on 2009-05-12 07:57
(Received via mailing list)
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) %>
6bf5a62e064a8419f8d9930573a315de?d=identicon&s=25 nishi (Guest)
on 2009-05-12 09:16
(Received via mailing list)
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.
This topic is locked and can not be replied to.