From: Wai-Sun Chia Date: 2002-08-12T17:08:13+09:00 Subject: Re: Handling forms on database driven websites Philip Mak wrote: > > which looks considerably nicer, but still feels too tedious when I'm > building a website that has many of these forms to make. I also find > myself having to duplicate my data definitions; Ruby sees this: > > 'name' => ['Name', Forms::Text, {'maxlength' => 20}], > 'email' => ['E-mail Address', Forms::Email], > 'phone' => ['Phone Number', Forms::Phone] > > And the MySQL sees another data definition for the same data: > > name VARCHAR(20) > email VARCHAR(80) > phone DECIMAL(10, 0) > > So, I am still in search of the perfect, minimal-effort way to > generate HTML for, and process the input of forms on a database-driven > website. > > Does anyone have any pointers to offer? > > P.S. I've heard people here say that PostgreSQL is better than MySQL. > How would it help in my situation? Yes it is. It has long has many of the features that MySQL is only beginning to take place (i.e. FK, ACID, etc.). But I don't think it'll help in your case as yours is not a DB-related problem. It is a paradigm-shear between your language (Ruby) and your medium (MySQL). This is as Ruby is a pure OO while MySQL or any RDBMS is not. The ideal case is to find a OODBMS and thus data will have a one-to-one mapping between Ruby and the OODBMS. Having said that I do not know of any viable Opensourced OODBMS around (I'm very happy if someone could confirm otherwise). Therefore, you could do a second-best solution is to have another level of indirection, a meta-data-definition. I have done this before using XML, below is an oversimplified sample: varchar 20 You could then write a Ruby layer to decode this and generate the Ruby class (which would be then be eval'ed dynamically later), and the MySQL/PostgreSQL SQL script. You could then write a DTD or XMLschema to manage the integrity of your XML-based Metadata Definition. After which you could generate a PageTemplate (it's great! I'm using it with fantastic results) form template, which could then be instantiated dynamically depending on what type of forms. This is an excellent solution if you have lots of similar forms, differing just is a couple of attributes or fields. -- Wai-Sun "Squidster" Chia Consulting & Integration Linux/Unix/Web Developer Dude