Skip to content

Instantly share code, notes, and snippets.

@joshuaclayton
Created February 26, 2009 14:45
Show Gist options
  • Save joshuaclayton/70881 to your computer and use it in GitHub Desktop.
Save joshuaclayton/70881 to your computer and use it in GitHub Desktop.
class ActiveRecord::Base
def self.nullify(*args)
callback = args.shift if ActiveRecord::Callbacks::CALLBACKS.include?(args.first)
self.send(callback || "before_validation", lambda {|model| args.each {|a| model.send("#{a}=", nil) if model.send(a).blank? }})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment