Created
March 28, 2009 18:24
-
-
Save femoco/87166 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/initializers/nullify_blank.rb | |
| class ActiveRecord::Base | |
| def self.nullify_blank(*args) | |
| for arg in args | |
| define_method :"#{arg.to_s}=" do |v| | |
| v = nil if v.blank? | |
| self[arg.to_sym] = v | |
| end | |
| end | |
| end | |
| end | |
| # model | |
| class User < ActiveRecord::Base | |
| nullify_blank :author, :content | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment