This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 3a8f3c2e09bc953e9b5b76b5101c3691cb84a9b2
tree 5d41d3edb2e994fbcb934fe1fe34d0e977b12acb
parent e1d504c76e9a133d4f7c89748c6302066cdbd774
tree 5d41d3edb2e994fbcb934fe1fe34d0e977b12acb
parent e1d504c76e9a133d4f7c89748c6302066cdbd774
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Tue Dec 23 04:23:28 -0800 2008 | |
| |
README.markdown | Thu Jan 15 22:18:57 -0800 2009 | |
| |
Rakefile | Thu Jan 15 21:50:08 -0800 2009 | |
| |
clear_empty_attributes.gemspec | Thu Jan 15 21:50:08 -0800 2009 | |
| |
init.rb | Mon Feb 05 06:55:52 -0800 2007 | |
| |
lib/ | Mon Jun 16 04:17:06 -0700 2008 | |
| |
spec/ | Thu Jan 15 04:59:05 -0800 2009 | |
| |
tasks/ | Thu Jan 15 22:15:35 -0800 2009 |
README.markdown
Problem
When AR objects are saved, empty fields are saved as '' instead of nil.
- Complicates queries for empty fields (
WHERE field IS NULL OR field = '') - Makes the use of
unless field.blank?necessary (opposed to onlyif field) - Can lead to late-detected bugs because most of the time strings were
filled or ''and suddenly they arenil - Some validations do not support
:allow_blank=>true - Databases can handle
NULLbetter & faster than empty strings (especially when usingLIKE)
Solution
Defines an AR before_validation that sets empty Strings to nil.
Install
script/plugin install git://github.com/collectiveidea/clear_empty_attributes.git
OR
sudo gem install collectiveidea-clear_empty_attributes
Migration
When you are switching to clear_empty_attributes, run this task
to remove any '' strings/texts from your database.
rake db:clear_empty_attributes
(only works when checked out or installed as plugin)
TODO
Should work with update_attribute / write_attribute too








