github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

collectiveidea / clear_empty_attributes

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 7
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Click here to lend your support to: clear_empty_attributes and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

When Active Record objects are saved from a form, empty fields are saved as empty strings instead of nil. This kills most validations. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Regenerated gemspec for version 0.2.1 
grosser (author)
Sun Dec 13 02:25:57 -0800 2009
brandon (committer)
Sun Dec 13 16:07:05 -0800 2009
commit  af0961606580f7f51470f6d568760ef9a3e83b3c
tree    c4be0e6ac629e761736f433dd5deca083210f1ec
parent  52f9cf2039086179c392f98e542b613243a73763
clear_empty_attributes /
name age
history
message
file .gitignore Loading commit data...
file README.markdown
file Rakefile
file VERSION
file clear_empty_attributes.gemspec
file init.rb
directory lib/
directory spec/
directory tasks/
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 only if field)
  • Can lead to late-detected bugs because most of the time strings were filled or '' and suddenly they are nil
  • Some validations do not support :allow_blank=>true
  • Databases can handle NULL better & faster than empty strings (especially when using LIKE)

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 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)

Authors

  • Brandon Keepers
  • Michael Grosser

Hereby placed under public domain, do what you want, just do not hold anybody accountable...

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server