I our Rails app, we’d like to prevent a user from physically entering more characters in a text field than can be recorded in the corresponding database field. This seems much friendlier than letting him/her type too much and then be told to try again after the fact.
In other words, all View input text fields should have a maxlength= attribute set equal to the :limit of the corresponding ActiveRecord Model varchar() field.
Is there a way to cause this to happen automatically?
If not, is there a DRY idiom, helper function, or metaprogramming hack that will make it so?
Something like the following (untested) monkey patch might help