Search code examples
httpruby-on-rails-4simple-form

Search Form generating the wrong URL request


I am trying to performed a Search Form using Simple_Form gem. I need to select a value from a collection, do some calculation and return a result. The controller works, if I manually write de URL it will work. If I generate it with the form, the URL construction is not doing what I am expecting.

This is what I get:

http://0.0.0.0:3000/nearestVehicle?nearestVehicle%5Baddrnr%5D=0001

This is what I need to get:

http://0.0.0.0:3000/nearestVehicle?addrnr=0001

View:

 <%= simple_form_for :nearestVehicle, url: nearestVehicle_path, :method => :get do |f| %>
        <%= f.input :addrnr, collection: @all_addresses, :label_method => :addrname1 %>
        <%= f.button  :submit , name: nil%>
    <% end %>

What I am doing wrong?


Solution

  • Maybe it is not the nicest solution, but here is how I made it work:

    simple_form_for ''
    

    All form:

    <%= simple_form_for '', url: nearestVehicle_path, :method => :get do |f| %>
      <%= f.input :id, collection: @all_addresses, :label_method => :addrname1 %>
      <%= f.button :submit, value: "Buscar",:name => nil%>
    <% end %>
    

    Output:

    nearestVehicle?%5Baddrnr%5D=27
    

    Same as:

    nearestVehicle?[addrnr]=27