title: Rails - How to use hidden field on form to pass a value of an object related to the one created on a form?
body: <p>I am trying to pass an <code>rfid_tag</code> from a form that creates a <code>device</code> from a <code>hidden_field</code>.  Device <code>has_many rfids</code>.  The <code>rfid</code> already exists in the db.  </p>
  
  <p>Here is the code from the form:</p>
  
  <pre><code>&lt;th&gt;RFID Tag #&lt;/th&gt;
  &lt;td&gt;
    &lt;%= f.label(:@passed_rfid_tag, @passed_rfid_tag) %&gt;
    &lt;%= f.hidden_field :rfid_tag, :value =&gt; @passed_rfid_tag %&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>Here is the code from the devices_controller:</p>
  
  <pre><code>def create
     @cabinet = Cabinet.find(params[:device][:cabinet_id])
     @device = Device.create(params[:device])
     @device.rfids &lt;&lt; Rfid.where('rfid_tag' =&gt; params[:rfid_tag]).first
     @device.row_id = @cabinet.row_id
     @device.save
  </code></pre>
  
  <p>I get the following error because <code>rfid_tag</code> is not an attribute of <code>device</code>.  It is an attribute of <code>rfid</code>:</p>
  
  <pre><code>Can't mass-assign protected attributes: rfid_tag
  
  app/controllers/devices_controller.rb:182:in `create'
  </code></pre>
  
  <p>Thanks.</p>