[ARCHIVED] Trimifies string attributes of active record models before validation
Ruby
Switch branches/tags
Pull request Compare This branch is 9 commits ahead of grobie:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
Gemfile.lock
MIT-LICENSE
README.rdoc
Rakefile
VERSION

README.rdoc

Trimify

Trimify is an ActiveRecord Plugin that allows you to easily trim leading and trailing white spaces from string attributes and optionally turn blank strings to nil. Only attributes you specify will be checked and converted. Using trimify on non-string attributes has no effect.

Installation

gem install trimify

Example

class User < ActiveRecord::Base
  trimify :first_name, :middle_name       
  trimify :last_name, :nilify => false    # default value of :nilify is true
end

user = User.create(:first_name => " Shompet ", :middle_name = "", :last_name => "")
user.first_name   # => "Shompet"
user.middle_name  # => nil
user.last_name    # => ""

Continuous Integration

Acknowledgments

Trimify is inspired by the Nilify plugin written by Tobias Schmidt.

Copyright

Copyright © 2011 Behrang Saeedzadeh, released under the MIT license.