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| %>

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

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


This enables me to select a single product from a drop down menu of products. 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'}, {:multiple=>true}


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 sent.

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:

FORM: <p>   <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) %>   </select> </p>

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

Hope that helps some.