form_for radio_button rails

form_for radio_button rails

如何使用 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>

我试过了,这个不行 其他字段存储在数据库中 <%= f.radio_button :is_code, [a,1,b,2,c,3,d,4] %>

非常感谢您的帮助!

我看到所有其他 input 标签都有 integer 值,但在您的 f.radio_button 中,您将 value 设置为 '1',这是一个字符串,您可以检查您的验证或该属性正在等待接收的数据类型。

试试:

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

请注意 radio_button 的第二个 valueparameter 是它将采用的值,名称将是控制器,括号 controller[attribute] 上的属性。