boolean validation

I’m relatively new to Rails and was wondering what the reasoning behind the following is:

I have a boolean field processed that I want to set to false by default:

before_validation(on: :create) do

self.processed ||= false

end

validates :processed, presence: true

This only works if I modify it to the following, which with my knowledge don’t find intuitive:

before_validation(on: :create) do

self.processed ||= false

true

end

validates :processed, inclusion: { in: [true, false] }

Is this a design choice or is it simply too hard too implement (Object#blank etc)?

You can add the default false value to the DB column and if the value is nil, it will set it to false on save.

It is a design choice, see for example Redirecting to Google Groups for rationales.

These kinda default values are better to handled in the database IMO.

Thanks everyone, I’ll then keep using the inclusion validator and only set default values in the DB.