title: nested attributes + multi select: Couldn't find Collection with ID=["1", "2", "3"] for Product with ID=?
body: <p>I have a many-many relationship with <code>collections</code> is a multi-select field for <code>product</code></p>
  <p>products_controller.rb</p>
  <pre><code>def new
      @product = Product.new
      @product.collections.build
      @product.categories.build
      @product
  end
  
  def create
     @product = Product.new(product_params)
     ...
  end
  
  private
  def product_params
     params.require(:product).permit(:product_id, :name, :price, :popularity, 
          collections_attributes: [ id: [] ])
  end
  </code></pre>
  <p>products model</p>
  <pre><code>class Product &lt; ApplicationRecord
    validates :product_id, uniqueness: true
    has_and_belongs_to_many :collections, optional: true
    accepts_nested_attributes_for :collections, reject_if: -&gt;(attributes){ attributes['id'].blank? }, allow_destroy: true
  end
  </code></pre>
  <p>products view</p>
  <pre><code>    &lt;%= form.fields_for :collections do |fc| %&gt;
        &lt;%= fc.label :collections %&gt;
        &lt;%= fc.select(:id, Collection.all.collect { |c| [c.name, c.id] }, 
                      { include_blank: true, include_hidden: false }, {multiple: true}) %&gt;
      &lt;% end %&gt;
  </code></pre>
  <p>View will look like this as user has the option to select multiple collections
  <a href="https://i.stack.imgur.com/5QO5p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5QO5p.png" alt="view" /></a></p>
  <p>However, when I post to <code>/create</code>, it says</p>
  <p><a href="https://i.stack.imgur.com/84hc1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/84hc1.png" alt="error" /></a></p>
  <p>Log for <code>products_params.inspect</code></p>
  <p><a href="https://i.stack.imgur.com/B0WQn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B0WQn.png" alt="enter image description here" /></a></p>
  <p>Not quite sure what's wrong with it. Is it because <code>ids</code> can't take an array? If that so what is a solution for it.</p>
  <p>Any help would be appreciated. Thanks!</p>
  <hr />
  <p><strong>UPDATE</strong>
  whole product form. Please ignore <code>product_id</code> as it's not a primary key.</p>
  <pre><code>&lt;%= form_with(model: product, local: true) do |form| %&gt;
    &lt;% if product.errors.any? %&gt;
      &lt;div id=&quot;error_explanation&quot;&gt;
        &lt;h2&gt;&lt;%= pluralize(product.errors.count, &quot;error&quot;) %&gt; prohibited this product from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% product.errors.full_messages.each do |message| %&gt;
          &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div class=&quot;actions&quot;&gt;
      &lt;%= form.label :product_id %&gt;
      &lt;%= form.text_field :product_id %&gt;
  
     
      &lt;%= form.fields_for :collections do |fc| %&gt;
        &lt;%= fc.label :collections %&gt;
        &lt;%= fc.select(:id, Collection.all.collect { |c| [c.name, c.id] }, 
                      { include_blank: true, include_hidden: false }, {multiple: true}) %&gt;
      &lt;% end %&gt;
  
      &lt;%= form.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>