我有一个用于关联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 %>发布于 2013-03-18 23:36:51
你需要一个表单的提交按钮,一个link_to是不够的,除非它运行一些javascript来提交表单或通过选择。
<%= f.submit 'Link Device' %>https://stackoverflow.com/questions/15480409
复制相似问题