How do I select multiple things in a form??

Chris Finch wrote:

At the moment I have the following code:

<% form_for :query, :url => {:action => 'plot'} do |form| %>

        <label for "query_product_name"> Product: </label>
        <%= :product_name,
                        :prompt => "Select Product"

    <%=submit_tag "Display Results", :class => "submit"%>


This enables me to select a single product from a drop down menu of
It then saves this product in query object.

I want to be able to select multiple products and for them to be held as
an array in query.

Is this possible??


Posted via

Add ':multiple=>true' to the options hash for the select


try doing this.. :product_name, @products, {:prompt=>'select product'},


Chris Finch wrote:

I haven't got it to work quite yet.

When I select multiple products, I was hoping they would be sent as an
array to the query object.


When I select multiple products, only 1 product (the first one) gets

Do you know how to send them as an array?


Posted via

Give the control a name like :name=>'products[]'
put that in the second hash with the :multiple=>true


Chris, here is something I have:

  <label for="categories">Categories</label><br />
  <select id="categories" name="categories[]" multiple="multiple"
size="10" style="width: 250px;">
    <%= options_from_collection_for_select(@all_categories,
                         :id, :long_name,
                         @selected) %>

  def create
    @photo =[:photo])
    @photo.categories = Category.find(params[:categories]) if
      flash[:notice] = 'Photo was successfully created.'
      redirect_to :action => 'list'
      @all_categories = Category.find(:all, :order => 'name')
      render :action => 'new'

Hope that helps some.