简体   繁体   English

form_for radio_button rails

[英]form_for radio_button rails

How do I record this using form_for? 如何使用form_for录制此内容?

<div class="form-group">
        <div class="cc-selector">
        <%= f.radio_button :priorities, id: "yellow", name: "priorities", value: '1'%>
          <input id="a" type="radio" name="priorities" value=1/>
          <label class="priorities-cc yellow" for="a"></label>
          <input id="b" type="radio" name="priorities" value=2/>
          <label class="priorities-cc orange" for="b"></label>
          <input id="c" type="radio" name="priorities" value=3/>
          <label class="priorities-cc red" for="c"></label>
          <input id="c" type="radio" name="priorities" value=4/>
          <label class="priorities-cc fair" for="d"></label>
        </div>
      </div>

I tried, this don't work The other fields are stored in the database <%= f.radio_button :is_code, [a,1,b,2,c,3,d,4] %> 我试过,这不起作用其他字段存储在数据库中<%= f.radio_button:is_code,[a,1,b,2,c,3,d,4]%>

Thanks a lot for your help! 非常感谢你的帮助!

I see all the others input tags have an integer value, but in your f.radio_button you're setting the value as '1' , which is an string, you can check your validations or the data type that attribute is waiting to receive. 我看到所有其他input标签都有一个integer数值,但是在你的f.radio_button你将value设置为'1' ,这是一个字符串,你可以检查你的验证或属性等待接收的数据类型。

Try with: 试试:

<%= f.radio_button :priorities, 1, id: 'yellow', class: 'priorities-cc fair', for: 'd' %>

Note the second value or parameter for the radio_button is the value it'll take, the name will be controller and the attribute on brackets controller[attribute] . 注意, radio_button的第二个valueparameterradio_button采用的值,名称将是控制器,括号controller[attribute]上的controller[attribute]

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

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