Sunday, January 20, 2008

Rails custom formbuilder

Is there no better way to create custom tags than with your own formbuilder? So far, I'm not impressed. I've read through a couple examples and neither one has really satisfied my needs.
http://www.aldenta.com/2006/09/19/writing-a-custom-formbuilder-in-rails/
http://www.railsonwave.com/railsonwave/2007/5/2/create-a-color-picker-helper-with-formbuilder

The first one is fine if you create your own namespace so that all your form_for, fields_for work correctly. I really don't want to start tacking a bunch of names on to my form_for, fields_for. It just leaves a bad taste in my mouth.

What about the second example? You create a class and then use :builder => MyFormBuilder. Well, then you have to start creating the same methods for fields_for and for all the ajax methods. This isn't isn't DRY.

I'm probably missing something obvious here but my real argument is that I have to much around with rails at all to create my own custom tags. Why do I have to jump through a bunch of hoops to create my own special tags to be used in my forms? Why is Rails tying y hands rather than making it easier for me like the framework should?

I really only bring this up because I've used some of Hobo's features. It builds on top of Rails and adds some pretty great stuff. My favorite is DRYML. Basically, DRYML lets you define your own tags to be used as you need. You can override what is already there and create new tags based off of tags that already exist.

One of the best things is that the code that you write looks like HTML. Actually, it is a bit like XML but I forgive the devs. This is good because I can create a library of custom tags and then hand it off to our HTML developer to code to his hart's content. If, at some point, he comes up with some new HTML/JavaScript tag, then that can be added to the library and used pretty quickly.

If you are interested in creating web pages quickly I suggest you take a look at Hobo. It has some blemishes (bad documentation, a lot of coupling, still a new project) but I think that it has a lot of promise. The developers are working hard to fix some of the current problems one of them being the coupling. I'm seriously considering moving over to DRYML when they finally make a gem/plugin out of it.

No comments: