Forum: Ruby on Rails Multiple selectbox and params

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
gitte (Guest)
on 2005-11-23 17:02
(Received via mailing list)
Hi there,

I'm having some trouble figuring this one out:
I have a multiple select box. Selecting one option, the value gets
submitted just fine. Selecting two or more options, it's only the last
selected that get's submitted.

Gitte W.
nicholas.stuart (Guest)
on 2005-11-23 17:18
(Received via mailing list)
How are you using the select box? Are you tying it right to the model
If so this isn't going to work (that I know of).
Your <select> tag should look something like:
<select name="my_options[]">
Of course with all the other stuff needed as well. You'll notice the
name is
basically an array name which will allow you to pass as many values as
want for this option and can get it by doing something like

Hope this helps!
Per D. (Guest)
on 2005-11-23 18:15
I had a similar problem yesterday, even the same perhaps?

My guess is that it is in fact submitting all the values as an array but
you are not seeing it selected in the form because all the values in the
array are strings and not numbers.

What I did was before using the array in "selected_value" I turned all
the elements in the array to integers using to_i

Hope that helps you out.
Steven <> <> (Guest)
on 2005-11-23 18:49
I'm doing something similar that uses muliple select menus.

Here is the controller
def new()
  @side_menu = [ build_text_box('Instructions:', @required_text) ]

  if request.get?()
    @institution =
    if params[:commit].eql?('Cancel')
      return nil
      @institution =[:institution])
        flash[:notice] = 'Institution was successfully created.'
      	redirect_to :action=>'list'

  @license_types = LicenseType.find(:all);
  @license_type_ids = []
  @institution.license_types.each { |x| @license_type_ids << }

Here is code from my view

<% options =
                                        "name", "id", @license_type_ids)
<%= select_tag("license_type_ids[]", options, {:multiple=>true,
:size=>3}) %>


Hope this helps.

gitte (Guest)
on 2005-11-24 10:50
(Received via mailing list)
Nick S. wrote:
> Hope this helps!
> -Nick

Hi Nick,

Yeah it helped a lot - I didn't know you had to put [] on the name of
the input tag.

Well I actually have another problem, because I'm using the multiple
select in a form that's an AJAX observe_form. I'm not sure how to pass
the selected values in the :with parameter.

Gitte W.
nicholas.stuart (Guest)
on 2005-11-25 03:31
(Received via mailing list)
Glad it helped! Not so sure about the ajax part though. Only have used
the very basic parts of that as of yet.
This topic is locked and can not be replied to.