Radio buttons for boolean field, how to do a "false"?

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 by Object#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