title: Rails 3.1 - Trying to get check_box_tag to work with a lookup table
body: <p>I'm new to Rails and I've been having fun, that is until my struggles with <code>check_box_tag</code>.  I've read a lot of the questions on this site and I still haven't solved my problem.  I'm convinced it is something I am just missing.</p>
  
  <p>I have a <code>reportdetail</code> table and a <code>buginfo</code> table.  The <code>buginfo</code> table represents a readonly table of bugs I want to find in some program. The <code>reportdetail</code> table will hold reports that have will contain the list of bugs (from the buginfo table) that the user wants to find.  I can have many reports within the report detail table.</p>
  
  <pre><code>class Reportdetail &lt; ActiveRecord::Base
    has_many :buginfos
  end
  
  class Buginfo &lt; ActiveRecord::Base
    belongs_to :reportdetail
  end
  </code></pre>
  
  <p>Here is my schema.  It is simple:</p>
  
  <pre><code>ActiveRecord::Schema.define(:version =&gt; 20111221162309) do
  
    create_table "buginfos", :force =&gt; true do |t|
      t.string   "name"
      t.datetime "created_at"
      t.datetime "updated_at"
    end
  
    create_table "reportdetails", :force =&gt; true do |t|
      t.string   "name"
      t.integer  "buginfo_id"
      t.boolean  "bug_detected"
      t.datetime "created_at"
      t.datetime "updated_at"
    end
  end
  </code></pre>
  
  <p>And finally my partial _form.html.erb for <code>reportdetail</code>:</p>
  
  <pre><code>&lt;%= form_for(@reportdetail) do |f| %&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :name %&gt;&lt;br /&gt;
      &lt;%= f.text_field :name %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;table&gt;  
        &lt;% Buginfo.find(:all).each do |buginfo| %&gt;
          &lt;tr&gt;
            &lt;td&gt; &lt;%= check_box_tag("[buginfo_id][]",1,buginfo.id) %&gt; &lt;/td&gt;
            &lt;td&gt; &lt;%= buginfo.name %&gt; &lt;/td&gt;
          &lt;/tr&gt;
        &lt;% end %&gt;
      &lt;/table&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>The form correctly shows a check box next to every bug and I can even click the check boxes, however the data is never saved.  I know the first parameter for <code>check_box_tag</code> needs to be unique and I'm pretty sure this is correct.  I know the second parameter is the value of the checkbox, but what does this really mean?  I'm assuming this means the current value of whether this bug has been selected or not, but since I haven't selected anything yet, I'm not sure what to do.  According to the docs I read the third parameter should be "Is the check box checked or not?"  But once again, what is this relative to? - the current value or ...</p>
  
  <p>If the user is creating a new <code>reportdetail</code> and assuming there are 5 bugs in the buginfos database, I would assume 5 checkboxes to show up on the /reportdetail/new.  This happens correctly.  If I select 3 bugs for the reportdetail (selecting the checkboxes)  I would assume three records would be created in the database to represent each of the bugs the report wants to include.  This isn't happening at all. I just get one record and buginfo_id and bug_detected are both nil.</p>
  
  <p>Any guidance would be greatly appreciated.  Thanks for any help you can give me.</p>