目前我正在试图插入一些简单的真/假电台Rails的3个按键,但我不能找到一种方法,使一个单选按钮插入假。
I am currently trying to insert some simple true/false radio buttons in Rails 3, but I can't find a way to make a radio button insert "false".
我的code是如下:
<%= f.radio_button :accident_free, true %><label for="auction_accident_free_true">ja</label>
<%= f.radio_button :accident_free, false %><label for="auction_accident_free_false">nein</label>
我已经尝试过:
I already tried:
1/0 在1/0 在真/假 在真/假 在是/否但似乎没有任何工作正确的值false。我的字段设置为
but nothing seems to work right for the value false. My field is set with
validates_presence_of :accident_free
和我总是得到它必须被填充继续,点击假按钮时的消息。点击真正的按钮时,它工作正常,但假的不能得到认可。
and I always get the message that it has to be filled to continue, when clicking the false button. When clicking the true button, it works fine, but false doesn't get recognized.
有谁知道怎么做是正确的?
Does anyone know how to do it correctly?
在此先感谢
阿恩
这是它:
http://apidock.com/rails/ActiveRecord/Validations/ClassMethods/validates_$p$psence_of
validates_ presence_of()将验证指定的属性不为空(按对象#空白的定义?)
validates_presence_of() validates that the specified attributes are not blank (as defined by Object#blank?)
如果您想验证一个布尔字段(其中实际值是true和false)的presence,你会想用 validates_inclusion_of:FIELD_NAME,:在=&GT; [真,假]
If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in => [true, false]
这是由于方式对象#空白?处理布尔值: false.blank? #=&GT;真正的
This is due to the way Object#blank? handles boolean values: false.blank? # => true
我试图用一个支架的例子,1
和0
在
I tried your example using a scaffold and "1"
and "0"
as in
<%= f.radio_button :foo, "0" %>
<%= f.radio_button :foo, "1" %>
和他们的工作。
上一篇:如何使用Rails的4强参数与的has_many:通过关联?如何使用、参数、Rails、has_many
下一篇:Android的工作室 - 错误充气类com.google.ads.AdView错误、工作室、Android、com