Theocacao
Leopard
Design Element
Comment on "Rails validates_length_of and Fixnum"
by Scott Stevenson — Nov 01
Lee N says: The validates_* rules are applied to the models, not the controllers, so they deal with the model types of the data, not with the input text.

I'm not really sure what you mean by this. The validates_* are not limited to type checking. For example, look at validates_format_of. How could data objects get values if they don't interact with (and therefore, validate) user input?

Also, it's pretty traditional to make a telephone or zip a string anyway

Hmmm... well it's possible, but I'm not sure I'd say it's traditional. Unless you mean traditional for Rails?

since you're not likely to be doing numeric calculations on it, but are likely to reformat it.

I don't think I'd be doing reformatting at the controller or model level. The source data should be just a number and the view can massage it as necessary.

Do you have a reason for going numeric here?

Easier formatting, for one. It's guaranteed to be a number by the time it gets to the db.
Back to "Rails validates_length_of and Fixnum"
Design Element

Copyright © Scott Stevenson 2004-2015