I’m currently using validates_length_of to guard against buffer overruns
in the model and using js max_length in the views to try to “head it off
at the pass.” There are two problems with the approach I’m currently
First is that the length value is hardcoded in both the model and view
so that if I change the length of the string in the database, I have to
change the value in both the model validations and any view that uses
Second is that, in the model, I’ve got to list each attribute I want to
validate individually. Some of the models have a lot of attributes.
I’ve looked at using validates_each and that could help a little with
the second problem, but it’s still unwieldly listing each attribute.
For the model side of this, I’m thinking of writing a generic validation
that iterates through the attributes of a model object on a save or
update and if it’s a string or char type, get it’s size / limit from the
table column attributes and validate against that. That would seem to
give me immunity in the validation from changes in the column sizes.
For the view side, I’m thinking of a similar approach that feed’s the
maxlength with a value based, again, on the column size rather than a
Two questions. Anybody know of something like that that already exists?
Anybody think it’s not doable?