我有一个用于关联 RFID 和设备对象的表单。提交后,表单会自动传递 rfid 的 id。如何传递在 options_from_collection_for_select 中选择的设备的 ID?
这是表单中的代码:
<br/>
<div class="well">
<%= form_for(@rfid) do |f| %>
<table class="table table-bordered">
<tr>
<th>RFID Tag #</th>
<td>
<%= f.label(:@rfid, @rfid.rfid_tag) %>
<%= f.hidden_field :rfid, :value => @rfid %>
</td>
</tr>
<tr>
<th>Device Name</th>
<td>
<%= f.select :device, options_from_collection_for_select(Device.order(:name).where("rfid_tag IS NULL"), "id", "name_or_alternative", @device) %>
</td>
</tr>
</table>
<%= link_to "Link Device", { :controller => :devices, :action => :assign_rfid_to_device, :device => @device }, :class => "btn btn-primary" %>
<% end %>