【问题标题】:Ruby Radio buttons and hidden field not showing up with form_with urlRuby 单选按钮和隐藏字段未与 form_with url 一起显示
【发布时间】:2020-05-01 22:37:14
【问题描述】:

我正在尝试制作一个表单,其中有一个下拉菜单来显示我的所有商店,并且还有三个单选按钮供用户指示首选时间段。目前,他们都没有出现。

最终,我会将此表单的数据发送到我的一个控制器中的 calculate_stores 方法。

这是我的表格。

<%= form_with url: calculate_stores_path, method: :get, local: true do |f|%>
    <%= f.hidden_field :store_id %>
    <%= f.radio_button :set_time_span, '2 weeks', :value => 14 %>
    <%= f.radio_button  :set_time_span, '1 month', :value => 30 %>
    <%= f.radio_button :set_time_span, 'custom', :value => 0 %>

<% end %>

【问题讨论】:

  • 您是否验证了表单是否在浏览器的页面视图源中生成?
  • 是的,我尝试了一个日期选择器,结果很好。

标签: ruby-on-rails forms controller radio-button hidden-field


【解决方案1】:

radio_button 辅助方法用于访问表单中没有的对象上的特定属性。

radio_button_tag 是否更适合您的需求?

<%= form_with url: calculate_stores_path, method: :get, local: true do |f|%>
    <%= hidden_field_tag 'store_id' %>
    <%= radio_button_tag 'set_time_span', '2 weeks', :value => 14 %>
    <%= radio_button_tag 'set_time_span', '1 month', :value => 30 %>
    <%= radio_button_tag 'set_time_span', 'custom', :value => 0 %>
<% end %>

【讨论】:

  • @turtlefish12,试试把:set_time_span改成'set_time_span'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-30
  • 2013-01-20
相关资源
最近更新 更多