On Sep 3, 2:06 pm, Dave Howell <[email protected]> wrote: > > Validations are always specified by the user, and exist solely to > > provide nice error messages to the user (often on websites). > > I assume you mean specified by the *programmer*, to provide nice messages to > the user?
Correct :) > > If you are writing code that interfaces with the > > user, you'll want to add a validate method to your models and handle > > validation there. > > Sure, and I first started to do exactly that, by creating my own .valid? > method. Then I discovered there already was one. > > I'm just surprised that there doesn't seem to be a way to do something like > > plugin :validation_helpers > > def validate > super > validates_against_types > end There's validates_not_string, which when used in conjunction with the "raise_on_typecast_failure = false" setting, does a good job of reporting typecasting errors as failed validations. > especially since Sequel, generally, has been very (I would even say > astonishingly) clever about not making me tell it things that it can learn > directly from the database. Transforming database constraints into validations is possible, but not an easy problem to solve. In most cases, it would involve parsing SQL, which Sequel has a policy against doing. Even if the constraints could automatically be turned into validations, there's still the issue of presenting nice error messages to the user (other than just "is invalid"). Finally, I think it would create a maintenance burden. I think this type of code is best left to an external plugin. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
