Bill Walton
2007-Mar-02 20:27 UTC
Generic validation / maxlength off column[colname].limit ?
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 using. 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 the string. 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 hard-coded value. Two questions. Anybody know of something like that that already exists? Anybody think it''s not doable? Thanks, Bill --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Mar-02 20:52 UTC
Re: Generic validation / maxlength off column[colname].limit ?
> 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 > using. > > 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 > the string. > > 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 > hard-coded value. > > Two questions. Anybody know of something like that that already exists? > Anybody think it''s not doable?I can''t remember the name, but I''ve seen a plugin that will automatically turn your model validations into javascript validations... that would get you half way there... --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Mar-02 21:00 UTC
Re: Generic validation / maxlength off column[colname].limit ?
>> 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 >> using. >> >> 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 >> the string. >> >> 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 >> hard-coded value. >> >> Two questions. Anybody know of something like that that already exists? >> Anybody think it''s not doable? > > I can''t remember the name, but I''ve seen a plugin that will automatically > turn your model validations into javascript validations... that would get > you half way there...Found them. http://agilewebdevelopment.com/plugins/enforce_schema_rules http://agilewebdevelopment.com/plugins/client_side_validation --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton
2007-Mar-02 21:04 UTC
Re: Generic validation / maxlength off column[colname].limit ?
Hi Philip, Philip Hallstrom wrote:> Found them. > > http://agilewebdevelopment.com/plugins/enforce_schema_rules > http://agilewebdevelopment.com/plugins/client_side_validationSuper!!! Haven''t had a look yet but, worst case, that''s a big head start! Thanks! Bill --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---