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 Campbell <fraser-Txk5XLRqZ6CsTnJN9+BGXg@public.gmane.org> http://www.wehave.net/ Georgetown, Ontario, Canada Debian GNU/Linux --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Nice idea, I don''t have a clue if this is possible tho :-) Vish On 9/26/06, Fraser Campbell <fraser-eicrhRFjby5dCsDujFhwbypxlwaOVQ5f@public.gmane.org> wrote:> > > 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 Campbell <fraser-Txk5XLRqZ6CsTnJN9+BGXg@public.gmane.org> http://www.wehave.net/ > Georgetown, Ontario, Canada Debian GNU/Linux > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 Campbell <fraser-Txk5XLRqZ6CsTnJN9+BGXg@public.gmane.org> http://www.wehave.net/ Georgetown, Ontario, Canada Debian GNU/Linux --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Tuesday 26 September 2006 15:20, Fraser Campbell 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 Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---