Accessing validations from view

Hi,

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.


Fraser C. [email protected]
http://www.wehave.net/
Georgetown, Ontario, Canada Debian
GNU/Linux

Nice idea, I don’t have a clue if this is possible tho :slight_smile:

Vish

Hi,

I am part way through creating an autoform generator, and had same
question. Solved it with columns_hash.limit - see API doc,
ActiveRecord .

eg. For a model called Customer, referencing the field name using
field)

<% field_length_max=Customer.columns_hash[field].limit %>

Tony

On Thursday 28 September 2006 07:50, tonypm wrote:

I am part way through creating an autoform generator, and had same
question. Solved it with columns_hash.limit - see API doc,
ActiveRecord .

eg. For a model called Customer, referencing the field name using
field)

<% field_length_max=Customer.columns_hash[field].limit %>

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.


Fraser C. [email protected]
http://www.wehave.net/
Georgetown, Ontario, Canada Debian
GNU/Linux

On Tuesday 26 September 2006 15:20, Fraser C. wrote:

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?

Not with plain Rails. I suggest two of my plugins:

http://www.agilewebdevelopment.com/plugins/validation_reflection
http://www.agilewebdevelopment.com/plugins/client_side_validation

Michael


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs