This is my form
<%= 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 %>
If I print the on the console p @vehicles, you can see that there are values
#<ActiveRecord::Relation [#<Message id: nil, objectno: "Carlos">, #<Message id: nil, objectno: "HLPN">, #<Message id: nil, objectno: "024">, #<Message id: nil, objectno: "HLMAW">]>
However, when I select record from the collection @vehicles the URL does not contain a vehicle:
http://0.0.0.0:3000/temperature2?search=
I was expecting
http://0.0.0.0:3000/temperature2?search=Carlos
What I am missing?
Seems like you are missing value
properties in your generated HTML form. I guess you need to change the label_method
to value_method
in your form.
<%= f.input :search, collection: @vehicles, :value_method => :objectno, :label => 'Vehiculo', :selected => params[:search] %>