title: Rails/Ruby - Prepopulate form with data passed from another page
body: <p>How do I get values to prepopulate a new <code>device</code> form when navigating to it from <code>rfid</code> partial of <code>view/cabinet/show</code> page?  <code>device</code> has_one <code>rfid</code>.</p>
  
  <p>The link from cabinet/show:</p>
  
  <pre><code>&lt;%= link_to "Create New Device (non-functional)", new_device_path({:id =&gt; @rfid.id, cabinet_id: @cabinet.id}), :class =&gt; "btn btn-primary" %&gt;
  </code></pre>
  
  <p>The <code>devices_controller</code>, I want to have the create method work when either 0 or 2 params are passed:</p>
  
  <pre><code>def create(options)
  
  if options[:cabinet_id] and options[:id]
    @rfid = Rfid.find(params[:id])
    @device = Device.new(params[:device])
    @device.rfid = @rfid
    @device.cabinet_id = :cabinet_id
  
  else
    @device = Device.new(params[:device])
    @cabinet = Cabinet.find(params[:device][:cabinet_id])
    @device.row_id = @cabinet.row_id
  end
    respond_to do |format|
      if @device.save and @cabinet.refresh_capacity_used and @cabinet.refresh_consumption
        format.html { redirect_to @device, notice: 'Device was successfully created.' }
        format.json { render json: @device, status: :created, location: @device }
      else
        format.html { render action: "new" }
        format.json { render json: @device.errors, status: :unprocessable_entity }
      end
    end
  </code></pre>
  
  <p>end</p>
  
  <p>The cabinet_id and rfid portion of new <code>device/_form</code>:</p>
  
  <pre><code>&lt;tr&gt;
          &lt;th&gt;Cabinet&lt;/th&gt;
          &lt;td&gt;&lt;%= f.select :cabinet_id, options_from_collection_for_select(Cabinet.order(:name).all, "id", "name", @device.cabinet_id) %&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  
  &lt;tr&gt;
          &lt;th&gt;RFID&lt;/th&gt;
          &lt;td&gt;&lt;%= f.text_field :rfid, :value =&gt; params[:rfid]%&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  </code></pre>
  
  <p>Thank you.</p>