title: Rails : assign multiple params via form_for check_box for HABTM relationship
body: <p>I'm a rails noob working on my first own project. </p>
  
  <p>I got two models linked using a has_and_belongs_to_many relationship : Wine and Shop . To make it simple a wine can be sold in different shops and a specific shop can sell many different wines. Here are the models :</p>
  
  <pre><code>class Shop &lt; ActiveRecord::Base
   has_and_belongs_to_many :wines
  end
  
  class Wine &lt; ActiveRecord::Base
    has_and_belongs_to_many :shops
  end
  </code></pre>
  
  <p>My goal is to make a form to create instances of Wine including the Shops where the wine can be purchased. Here is my wines_controller :</p>
  
  <pre><code>  def new
      @wine = wine.new
      @shops = Shop.all
  
     respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @wine }
      end
    end
  
   def create
      @wine = Wine.new(params[:wine])
      params[:shops].each do |id|
        @wine.shops &lt;&lt; Shop.find(id)
      end 
  end
  </code></pre>
  
  <p>Here is my _form view rendered in new view :</p>
  
  <pre><code>&lt;%  @shops.each do |t|  %&gt;
  &lt;%= f.label t.name  %&gt;
  &lt;%= f.check_box :shops, t.id %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I've tried many things and spent hours on this but can't found the solution. Among other things I had a look at those issues but I could not get it working : </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/15188936/rails-create-form-for-model-with-many-to-many-relation">Rails create form for model with many to many relation</a></li>
  <li><a href="https://stackoverflow.com/questions/2263333/update-values-of-checkbox-with-habtm-relationship-rails">update values of checkbox with HABTM relationship -- Rails</a></li>
  <li><a href="https://stackoverflow.com/questions/16107343/creating-multiple-records-in-a-habtm-relationship-using-a-collection-select-ra">Creating multiple records in a HABTM relationship using a collection_select - Rails</a></li>
  </ul>
  
  <p>Lastly I got an</p>
  
  <pre><code>undefined method `merge' for 3:Fixnum
  </code></pre>
  
  <p>Just let me know if you need any other details to deal with this issue or if there is already a question about this that I have missed.</p>
  
  <p>Thanks in advance</p>