On 4/30/2014 3:14 AM, Jacob Carlborg wrote:

There's a plugin [1] for Rails for generating a form based on a type. I
don't understand how anyone can manage without that. It can
automatically respond in a couple of formats as well. By default JSON,
XML and Erb template. The most basic example will look something like this:


Automatic forms generated from a type are nice for quick-n-dirty stuff, but I find they tend to work against (or at least be much less useful for) the tweaking and customization usually needed in public-facing production sites.

So I started doing it in reverse:

Instead of defining the form in the server-side code and then awkwardly trying to make it generate the HTML I want, I just define the form in HTML. (Or rather, in an HTML template that's still more-or-less valid HTML, with a few additional non-standard tags to help with metadata like "how to validate this field").

Then I use Adam's dom.d (in non-strict mode) to read the HTML form template (preserving the templating stuff), and automatically infer everything I need to automate the form's behavior (and to strip out the non-standard metadata I added).

I've been pretty happy with that so far. It combines the DRY simplicity of "define a form in ONE place and it 'just works'" with the full power and control of hand-written HTML.

What I really need to do is fully de-entange that stuff from my cluttered mess of a homemade web framework <https://github.com/Abscissa/SemiTwistWeb> and release as a separate cleaned-up lib.

Reply via email to