ActiveRecord Plugin to set default values to nil
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
MIT-LICENSE
README.rdoc
Rakefile
init.rb

README.rdoc

Nilify

Nilify is an ActiveRecord Plugin that allows you to easily convert default values to nil. Only attributes you specify will be checked and converted.

Default values are:

String:   ""
Numeric:  0
Time:     1970-01-01 00:00:00

Installation

script/plugin install git://github.com/grobie/nilify.git

Example

class User < ActiveRecord::Base
  nilify :name, :salary, :birthday
end

user = User.create(:name => "", :salary => 0, :birthday => Time.parse("1970-01-01"))
user.name       # => nil
user.salary     # => nil
user.birthday   # => nil

License

Copyright © 2009 Tobias Schmidt, released under the MIT license