简单形式不发送参数

Simple form not sending parameter

这是我的表格

    <%= simple_form_for '', url: temperature2_path, :method => :get do |f| %>
        <%= f.input :search, collection: @vehicles, :label_method => :objectno, :label => 'Vehiculo',  :selected => params[:search] %>
        <%= f.button :submit, value: "Buscar",:name => nil%>
    <% end %>

如果我在控制台上打印 p @vehicles,你可以看到有值

#<ActiveRecord::Relation [#<Message id: nil, objectno: "Carlos">, #<Message id: nil, objectno: "HLPN">, #<Message id: nil, objectno: "024">, #<Message id: nil, objectno: "HLMAW">]>

但是,当我 select 从集合 @vehicles 记录时 URL 不包含车辆:

http://0.0.0.0:3000/temperature2?search=

我在期待

http://0.0.0.0:3000/temperature2?search=Carlos

我错过了什么?

您生成的 HTML 表单中似乎缺少 value 属性。我想您需要将表单中的 label_method 更改为 value_method

<%= f.input :search, collection: @vehicles, :value_method => :objectno, :label => 'Vehiculo',  :selected => params[:search] %>