title: Rails has_many :through and collection_select with multiple
body: <p>I have the following problem using a has_many :through many-to-many relation in a multi-select via collection_select :multiple => true. I have Suppliers who deliver many Ingredients which can be delivered by many Suppliers. Have a look:</p>
  
  <p>The Ingredient model:</p>
  
  <pre><code>class Ingredient &lt; ActiveRecord::Base
    has_many :ingredient_suppliers
    accepts_nested_attributes_for :ingredient_suppliers, :allow_destroy =&gt; true
  
    has_many :suppliers, :through =&gt; :ingredient_suppliers
  end
  </code></pre>
  
  <p>The Supplier model:</p>
  
  <pre><code>class Supplier &lt; ActiveRecord::Base
    has_many :ingredient_suppliers
    has_many :ingredients, :through =&gt; :ingredient_suppliers
  end
  </code></pre>
  
  <p>The relationship Entity:</p>
  
  <pre><code>class IngredientSupplier &lt; ActiveRecord::Base
    belongs_to :ingredient
    belongs_to :supplier
  end
  </code></pre>
  
  <p>And this is the form. Note that I could not get it to work without specifying the :name:</p>
  
  <pre><code>&lt;%= form_for(@ingredient) do |f| %&gt;
   &lt;%= f.fields_for :suppliers do |supplier_fields| %&gt;
        &lt;%= supplier_fields.collection_select (:supplier_ids, 
              Supplier.all(:order=&gt;"name ASC"), 
              :id, :name, 
              {:selected =&gt; @ingredient.supplier_ids, 
               :include_blank =&gt; true}, 
              {:multiple =&gt; true, 
                :name =&gt; 'ingredient[supplier_ids]'}) %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>If I remove the :name, then I get this error message:</p>
  
  <pre><code>Supplier(#-617951108) expected, got Array(#-608411888)
  
  Request
  
  Parameters:
  
  {"commit"=&gt;"Anlegen",
   "authenticity_token"=&gt;"MuEYtngwThharmM1KaAbH8JD3bScXiDwj0ALMytxl7U=",
   "_method"=&gt;"put",
   "utf8"=&gt;"✓",
   "id"=&gt;"1",
   "ingredient"=&gt;{"name"=&gt;"Ingredient 1",
   "nr"=&gt;"00100",
   "unit"=&gt;"kg",
   "mol_per_unit"=&gt;"2000,
  00000",
   "description"=&gt;"",
   "suppliers"=&gt;{"supplier_ids"=&gt;["1",
   "2"]}}}
  </code></pre>
  
  <p>The problem now is, that the PUT parameters only contain one supplier_id instead of an array of supplier_ids:</p>
  
  <pre><code>"ingredient"=&gt;{"name"=&gt;"Rohstoff 3", "nr"=&gt;"00300", "unit"=&gt;"Stk.", "mol_per_unit"=&gt;"0,00000", "description"=&gt;"", "supplier_ids"=&gt;"2"}
  </code></pre>