Hey Chris, thanks for the awesome and details response, and so quickly too!
Great details consideration there, I think you're right on the money with the two points around callbacks and gems/dependencies. I am just always playing devils advocate when I consider implementing something ;)
Funnily enough, out the probably 10 gems out there for stripping attributes (with widely varied adoption/stars), I also landed on that one
I've implemented it just before, and it definitely working nicely compared to my own initial attempt at implementing the strip/squish methods on the models.
I think you've also settled the case nicely regarding at the database (eg Postgres) vs Model, since at the database is often too late for things like validations in Ruby/Rails etc.
Thanks again for the detailed and quick answer, onto solving the bigger problems now! ;)
I've got an interesting question, and I'm sure you're all handling it in different ways. I know there are plenty of ways to tackle this problem, so I was interested in what everyone's doing?
The old issue of removing excess trailing/intermittent/leading whitespace, other characters from copying pasting etc, from user input?
user.first_name = "John "
user.email = "firstname.lastname@example.org\n "
etc etc, you all know what I mean.
I see this cleansing/normalisation could happen at a few stages:
Inside the Controller on Params Submission
Intermediate Model/Attribute Methods (Callbacks, even :o )
Prior to or upon Database Persistence (at the DB Specific level)
*What stage are people doing it at? *
Personally: I feel like the best place for this would be at the model level, as the gatekeeper for the database, but I always try to avoid callbacks wherever possible, just not sure if this would be an appropriate time to use them, or if anyone has a more elegant solution?
I see that there are a few gems out there too , but once again, always trying to minimise the number of dependencies I have in the project and keep the Gemfile lean ;)