I spent a while going through API docs but couldn't figure this out. Is there
a way to access a model's validation scheme from within the view?
I would like to do this so that I can programmatically generate form fields.
If this can be done then I will do things like:
- set maxlength of form fields to :maximum (from validates_length_of)
- put an asterisk (or whatever) beside any fields that have validations and
allow_nil is not true - to indicate that it is a required field
- etc.
I realize that the user can submit the form and get all the feedback he needs
anyway but I just think it would be nice to help out the user a bit on the
initial form.
Cool thanks. Yes that gets me part way. This method seem to look
specifically at the information active record has gathered from the database
tables - that does give a reasonable assumption of maxlength but it doesn't
let me know whether allow_nil has been set to true or not in the validation.