Nick J


2,260 Experience
22 Lessons Completed
0 Questions Solved


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 strip_attributes!

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! ;)

Hey all!

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?

An example:

user.first_name = "John " = "\n "

etc etc, you all know what I mean.

I see this cleansing/normalisation could happen at a few stages:

Immediately Upon User Form Input - ala Javascript functions to strip as they type/pre-submission
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 ;)