On Jun 21, 2010, at 11:43 AM, Eugueny Kontsevoy wrote: > That conversion works fine. And that could be a part of core html helpers. > What I would really like to borrow from Rails is the concept of models being > in charge of their own data validation. Is it a good move in theory? Perhaps > not. But after 3 years of Rails I am certain it works great in practice.
I guess the reason this never appealed to me was that my forms never match my models. My models are generally complex in structure, so my form might ask for 2-5 fields to be filled in, and from that will end up manipulating and updating information in multiple tables. So no single model validation would work, I need something specifically to validate the form that is being filled in, which rarely has a clean mapping to a single model class. I guess in that regard I somewhat envy the people that only create websites where every form cleanly maps to a single model. I just don't want to go through the effort of creating the model's, getting the whole thing ready, then finding out that they failed validation before saving them. That also confuses the issue of what the problem really was, did I not properly populate the model's, thus their validation failed? Or was the input from the user that I put into the model classes invalid and thus they failed validation? > Rails achieves that by tightly coupling their views and models. Pylons is > more modular so that door's closed and it's fine. I, for one, can't come up > with anything smarter than FormEncode to have both validators + decoupled > views/models. And I still do all my validation manually in my models, i.e. my > form classes are just a boilerplate shim which connects model-based data > validation with HTML form parsing/generation. If I had more time to hack for > fun, I would definitely be looking at getting rid of them. It still baffles me why Rails (and I guess Django?) works this way, I can understand the simple use-case, but I so rarely see forms out there that actually satisfy this simple use-case except in simple demo apps for learning the framework. How come people don't get pissed that they can't validate their form data *before* they go to the effort of setting up the actual model instances and preparing to save them? Aren't they interested in whether the data they're dumping into them is valid before their model validator kicks it out? How do you properly tell the user the difference between an error in what *they* gave you, vs. an error in how *you* setup the model instances which perhaps resulted in an invalid model? I'd really hate to tell the user their form was wrong when in reality there was a bug in how I populated the model instances. I suppose this explains why I didn't copy the concept into Pylons. :) If there's a solid answer to each of these questions though, then perhaps I missed something in how Rails handles it, and I'm totally open to hearing how these are resolved. Cheers, Ben -- You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en.
