我有以下代码:
<% 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(boolean) 值时遇到困难,因此我学会了验证您需要执行的操作:
validates_inclusion_of :carbonated, :in => [true, false]
关于ruby-on-rails - Rails form_for radio_button “Can'不能为空”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1178988/