0

我有一个用于关联 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 %>

4

1 回答 1

0

您需要一个表单的提交按钮,一个 link_to 是不够的,除非它运行一些 javascript 来提交表单或通过选择。

<%= f.submit 'Link Device' %>
于 2013-03-18T15:36:50.587 回答