A Must-Have Rails Plugin: strip_attributes

Posted by Scott on Dec 2nd, 2007

I recently discovered that my Rails model validations could be easily bypassed or broken by adding whitespace to the beginning or end of strings as they are entered in forms. For example, if your user account system is based on the uniqueness of email addresses, “joe@example.com” and ” joe@example.com” would validate as unique. This is something that nearly every webapp I can think of would want to avoid.

Fortunately there is a simple Rails plugin, strip_attributes, which will take care of this easily and efficiently. You can enable it on a per-model or per-field basis if you need fine-grained control. See the Rails wiki for more details.

In other news, there will be no December meeting of the NH Ruby and Rails User Group. Enjoy the holidays!

One Response

  1. Ryan McGeary Says:

    Hi. I know this is an old blog post, but I finally got around to turning this old plugin into a gem. v0.9 works with Rails 2 and v1.0 works with Rails 3.

    https://github.com/rmm5t/strip_attributes

    If not directly useful, maybe future onlookers will find value.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Blog Badges



[FSF Associate Member]

Archives