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.
On Thursday, March 6, 2014, Michael Imstepf <[email protected]> wrote: > 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 received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to > [email protected]<javascript:_e(%7B%7D,'cvml','rubyonrails-core%[email protected]');> > . > To post to this group, send email to > [email protected]<javascript:_e(%7B%7D,'cvml','[email protected]');> > . > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
