Save All Empty Strings as NIL

With the  clear_empty_attributes plugin, all empty string worries are gone!

  • Complicate queries for empty fields (WHERE field IS NULL OR field = '')
  • Use of unless field.blank? (opposed to only if field)
  • Late-detected bugs because most of the time columns were filled or '' and suddenly they are nil
  • Some validations do not support :allow_blank=>true
  • Datebases can handle NULL better & faster than '' (especially when using LIKE)

Install

script/plugin install git://github.com/grosser/clear_empty_attributes.git

Now all empty strings will be saves as NULL.

Migrate

To take care of all other/old models we have to run a migration.
Remove any blank strings/texts from your Models:

rake clear_empty_attributes:clear_all_blank_strings MODELS=User,Movie,...
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s