我有以下代码:
<% form_for(@libation) do |f| %>
<%= f.radio_button :carbonated, true %> <%= f.label :carbonated, "Yes" %>
<%= f.radio_button :carbonated, false %> <%= f.label :carbonated, "No" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
carbonated数据库中的列是类型tinyint.
当上面运行并且我点击时,No我得到一个大红框告诉我:
1 error prohibited this libation from being saved
There were problems with the following fields:
* Carbonated can't be blank
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
-thanx
ern*_*son 15
我对布尔值的验证有困难,所以我学会了验证你需要做的存在:
validates_inclusion_of :carbonated, :in => [true, false]
Run Code Online (Sandbox Code Playgroud)