2005-01-20

Rails is smarter than you (or, at least me)

I'm going back through the Rails tutorial that I mentioned last post, only using PostgreSQL 8.0.0 instead of MySQL this time, and discovered something very, very nice about Rails.

The tutorial (for those of you who haven't gone through it—and if you haven't, you should; it won't take long, and I can wait—has you create a database table for storing items on a todo list. There's a column called "done" of type integer; 1 means "done" and 0 means "not done". My first time through the tutorial I followed these directions, but this time I made the "done" column of type boolean because, well, it makes more sense and PostgreSQL has that data type.

Before, Rails presented the edit field for the "done" value as a text field. This time, with a boolean behind it, Rails presented it as a select list from which "True" or "False" can be chosen. In other words, Rails is smart enough not only to detect the table columns for itself, it's smart enough to realize that the possible values are constrained and change the default UI to something more appropriate.

Now, one could argue that for a boolean not null column, the UI element should really be a checkbox, but that would be nitpicking.

1 Comments:

At September 29, 2007 at 9:57 PM, Blogger Jesse said...

Hey all --

I'm beginning in ruby & rails after 14 months independent/craft work in php at http://listenlight.net. View my rails app at http://gravityway.com.

I'd like to meet up with your collective some time soon.

e-mail: tefflox /@ gmail /. com

cheers :-)

 

Post a Comment

<< Home