title: How can I use has_many relation with select?
body: <p>Given <code>Problem</code> &amp; <code>Observer</code> model:</p>
  
  <pre><code>class Problem &lt; ActiveRecord::Base
    has_many :observers
    accepts_nested_attributes_for :observers
  end
  
  class Observer &lt; ActiveRecord::Base
    belongs_to :problem
    belongs_to :user
  end
  </code></pre>
  
  <p>I am trying to use <code>form_for</code> to select users as observers:</p>
  
  <pre><code>        &lt;%= f.fields_for :observers do |obs| %&gt;
              &lt;%= obs.collection_select(:user_id, Users.to_a, :id, :name, {:include_blank =&gt; true, include_hidden: false}, {:multiple =&gt; true}) %&gt;
          &lt;% end %&gt; 
  </code></pre>
  
  <p>However Rails generates wrong name for select: <code>problem[observers_attributes][0][user_id][]</code>, so even creating a rule for strong_params (<code>{:observers_attributes =&gt; [{:user_id =&gt; []}]}</code>) it creates wrong relationship, only problem_id goes to the database, and all user_id are being ignored.</p>
  
  <p>What I'm trying to do is to show all users in multiple select, grab IDs and create association for them in <code>Problem#new</code> method.</p>
  
  <p><strong>UPDATE 12.10</strong></p>
  
  <p><strong>Posted Parameters:</strong></p>
  
  <p>Parameters: <code>{"utf8"=&gt;"✓", "authenticity_token"=&gt;"NHDl/hrrFgATQOoz9A3OLbLDAbTMziKMQW9X1y2E8Ek=", "problem"=&gt;{"problem_data_attributes"=&gt;{"title"=&gt;"safasfasfafsasf", "description"=&gt;""}, "observers_attributes"=&gt;{"0"=&gt;{"user_id"=&gt;["5", "8"]}}}}</code></p>
  
  <p><strong>Strong Params:</strong></p>
  
  <pre><code>def problem_params
   params.require(:problem).permit({:files_attributes =&gt; [:attach_id]}, {:observers_attributes =&gt; {:user_id =&gt; []}}, {:problem_data_attributes =&gt; [:title, :description]})
  end
  </code></pre>
  
  <p><strong>Create method</strong></p>
  
  <pre><code>def create
   @problem         = @project.problem.build(problem_params)
   @problem.account = current_account
  
   if @problem.save
    render :json =&gt; {status: true, id: @problem.id}
   else
    respond_with(@problem)
   end
  end
  </code></pre>
  
  <p><strong>And SQL that creates observer during create call</strong>:</p>
  
  <pre><code>SQL (0.2ms)  INSERT INTO `observers` (`problem_id`) VALUES (96)
  </code></pre>