A Must-Have Rails Plugin: strip_attributes
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!
August 15th, 2011 at 9:15 am
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.