【问题标题】:Simple form not sending parameter简单表单不发送参数
【发布时间】:2017-03-18 05:12:53
【问题描述】:

这是我的表格

    <%= 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">]>

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

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

我期待

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

我错过了什么?

【问题讨论】:

  • 我认为你需要在 input 元素中使用 name 属性

标签: ruby-on-rails forms ruby-on-rails-4 simple-form


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多