extract validation from ActiveRecord
Sometimes I have forms with no obvious AR counter-part that I'd like to validate using AR's excellent validation module. It can be done but not without some hacking. It would be nice to be able to mix in validation support to any class.
13 comments
-
David James
commented
We have ActiveModel in Rails 3. Doesn't it have what this request wants? Let's close this one out.
-
kazuyoshi tlacaelel
commented
I agree that model is the driest, if you need too complex validations put them in a mixin or a library and call what you need. I think that integrating validation to the form object is an interesting idea though. but it is kinda that way already if you think of it.
-
Nathan Youngman
commented
Having validation down at the model level is great, but I have definitely needed validation for forms that didn't fit that mold (user-created forms). Greater flexibility seems like a necessity when becoming ORM agnostic as well.
Ideally a nice DRY method for doing both client-side (UJS) and server-side validation for models and any other forms. Django forms may provide inspiration, and apparently DataMapper too.
-
eltiare
commented
FYI You can use DataMapper's validations like that: http://gist.github.com/50106
-
eltiare
commented
As an FYI, you can use DataMapper's validations on any class.
-
awattscurnow
commented
Validatable has levels and groups and I wish activerecord had this.
-
zdzolton
commented
-
Soleone
commented
Sounds really like an interesting and useful idea to me. Maybe create something like ActiveModel with no DB backend (as a Mixin) or somehow else get the validators in the forms.
-
konstantin.k commented
I think the "dryest" place for Validation is in the model and i think theres no need to make it more complex. but if the validators would be more modular to include and use them in any class in apps/model
-
kakutani
commented
I'd like to use validation with ActivePresenter.
-
cheapRoc
commented
validatable gem FTW
-
a_matsuda
commented
ActiveModel! ActiveModel!!
-
randlaeufer
commented
How is this not on the top of the list?