简体   繁体   English

Ruby 单选按钮和隐藏字段未显示为 form_with url

[英]Ruby Radio buttons and hidden field not showing up with form_with url

I'm trying to make a form where I have a dropdown to display all my stores, and also have three radio buttons for the user to indicate a preferred time period.我正在尝试制作一个表单,其中有一个下拉列表来显示我的所有商店,并且还有三个单选按钮供用户指示首选时间段。 Currently, none of them are showing up.目前,他们都没有出现。

Eventually, I'll be sending the data of this form to a calculate_stores method in one of my controllers.最终,我会将此表单的数据发送到我的一个控制器中的 calculate_stores 方法。

Here is what I have for the form.这是我的表格。

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

radio_button helper method is used for accessing a specific attribute on an object which you dont have in your form. radio_button辅助方法用于访问您的表单中没有的 object上的特定属性。

Properly radio_button_tag suites your need better?正确的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 %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM