Forum: Ruby on Rails non model select_tag problem

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.
5eb7dc9121bd474726f9f5568c9573ed?d=identicon&s=25 Per Djurner (pernod)
on 2005-11-22 19:59
What am I doing wrong here:

select_tag('website_ids[]',
options_from_collection_for_select(Website.find_all, 'id', 'name',
params[:website_ids]), {:multiple => true, :size => 5})

It works fine except that it does not display the selected options once
the form is submitted (it submits to the same page). The
"params[:website_ids]" part has to be wrong somehow, right?
Acd864a79c581fd5f7203ec993896c10?d=identicon&s=25 Deepak Surti <dmsurti@gmail.com> <dmsurti@gmail.co (Guest)
on 2005-11-22 20:22
Try @params[:website_ids]

Alternatively I have done it like this:

<% receivers = @dealing.receivers if @dealing.receivers%>
<%=
select_tag("receivers[]",options_from_collection_for_select(Party.find_all,
"id","name",receivers),{:multiple =>true})%>

I have a multiselect receivers tag . Each Dealing class has and belongs
to many receivers aka parties.

Hope this helps.
5eb7dc9121bd474726f9f5568c9573ed?d=identicon&s=25 Per Djurner (pernod)
on 2005-11-22 22:25
Thanks, still does not work though.

I should point out that it works with this code:
select_tag('website_ids[]',
options_from_collection_for_select(Website.find_all, 'id', 'name',
[1,3,5]), {:multiple => true, :size => 5})

The only thing different is that "params[:website_ids]" is replaced with
the hard coded "[1,3,5]".
5eb7dc9121bd474726f9f5568c9573ed?d=identicon&s=25 Per Djurner (pernod)
on 2005-11-23 00:30
Solved it now, the problem was that the params[:website_ids] array was
an array of strings and not integers so I had to convert each element of
the array to an integer using .to_i before I could use it in the
options_from_collection_for_select tag method.
This topic is locked and can not be replied to.