Skip to content

Instantly share code, notes, and snippets.

@henrik
Created November 27, 2010 10:11
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/717764 to your computer and use it in GitHub Desktop.
Save henrik/717764 to your computer and use it in GitHub Desktop.
ActiveRecord mixin to save NULL instead of empty strings to database.
module NullifyBlankAttributes
def write_attribute(attr_name, value)
new_value = value.presence
super(attr_name, new_value)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment