Best practice for removing leading and trailing whitespaces

I want to remove the leading and training spaces for most of the
resources in my rails application

For a new POST request, rails does the xml parsing and passes the params
hash to the controller. Some of the parameters have leading and/or
trailing whitespaces which are causing problems (e.g. new resources
being created rather than using the old ones). I don't want to put the
code in all the controllers to strip the whitespaces for different
resources/params.

I did find the following pattern:
http://scottmoonen.com/2009/05/08/rails-pattern-trim-spaces-on-input/

Is there another better approach to solve this? I was thinking of
configuring controller xml parser to remove these whitespaces. Is that
possible?

Thanks,
-Rakesh

That looks like the ideal way to do it. This sort of thing belongs in the model as it will stop you from making a mistake that one time you use ./script/console to make that one change....

I'm sure you *could* modify the XML parser, but why? The moment you add another way to access the data you'd have to do it there as well. And what if you have a field that you want to allow white space?

-philip