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\".
My code is the foll
This is it:
http://apidock.com/rails/ActiveRecord/Validations/ClassMethods/validates_presence_of
validates_presence_of()
validates that the specified attributes are not blank (as defined byObject#blank?
)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]
This is due to the way
Object#blank?
handles boolean values:false.blank? # => true
I tried your example using a scaffold and "1"
and "0"
as in
<%= f.radio_button :foo, "0" %>
<%= f.radio_button :foo, "1" %>
and they worked.
I recently came to another solution for this:
validates_presence_of :accident_free, :if => 'accident_free.nil?'
Explanation here