Skip to content

Instantly share code, notes, and snippets.

@latentflip
Created February 10, 2011 14:52
Show Gist options
  • Save latentflip/820638 to your computer and use it in GitHub Desktop.
Save latentflip/820638 to your computer and use it in GitHub Desktop.
Fails validation, but the_model.errors will be empty.
class TheModel < ActiveRecord::Base
def before_validation_on_create
#do some stuff
setup_defaults
end
private
def setup_defaults
self.expense ||= true
self.income ||= false
end
end
obj = TheModel.new
obj.valid? #=> false
obj.errors.count #=> 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment