gpt4 book ai didi

ruby-on-rails - Rails form_for radio_button "Can' t 为空”

转载 作者:行者123 更新时间:2023-12-02 06:25:47 34 4
gpt4 key购买 nike

我有以下代码:

<% form_for(@libation) do |f| %>
<%= f.radio_button :carbonated, true %> <%= f.label :carbonated, "Yes" %>
<%= f.radio_button :carbonated, false %> <%= f.label :carbonated, "No" %>
<% end %>

数据库中的carbonated列是tinyint类型。
当上面的代码运行时,我点击 No 我得到一个红色的大框告诉我:

1 error prohibited this libation from being saved
There were problems with the following fields:
* Carbonated can't be blank

有什么想法吗?
-谢谢

最佳答案

我在验证 bool 值时遇到了困难,所以我学会了验证它们的存在,你需要这样做:

validates_inclusion_of :carbonated, :in => [true, false]

关于ruby-on-rails - Rails form_for radio_button "Can' t 为空”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1178988/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com