links
300 Images From 1800 Sites
Punctuated Productivity
ascii table
brainjar.com: css positioning
Catman's Reference Guide to XHTML 1.1
Catman's XHTML 1.1 Elements and Attributes Reference Guide
citeseer
Color Scheme Generator
common errors in english
cool images
Copying music between authorized computers with iTunes for Windows
css layout-o-matic
daypop
del.icio.us
elegant hack
emacs wiki
floatutorial
imho...
keystroke shortcuts for windows xp
mozilla keyboard shortcuts
NameVoyager
perldoc.com
programming language popularity
regular expression tester
selectoracle
short url services
simple urls for search engines
the unix acronym list
yahoo dictionary

permalink

replication in rails

I’m working on a project that has 3 tables that are very similar and each should have a very similar edit UI. Of course I don’t want to duplicate code or coding effort if I don’t have to. I’m always trying to explore new areas of ruby and rails and this seemed like a good opportunity.

My first thought was to copy the scaffolding generator. I think most of the generators are pretty trivial but scaffolding is significant since it does reflection on the database in order to build the new and edit forms. Copying and modifying the scaffold generator was a bigger job than I expected but I got it working. Since the scaffold generator invokes the model generator I ended up modifying model too.

A modified generater is neat because you can make a change to the generator and completely regenerate the model, controller and views instantly.

I wasn’t satisfied with this though. Basically I now had a lot of automatically generated code. In addition I worked on it longer than if I had simply used the default scaffold generator and modified the forms and controllers individually.

It seemed to me that if you can run a generator 3 times you should be able to refactor things so that you only have one copy of that code instead of 3.

I wanted to experiment with run time code generation like rails associations (and many other features of rails). So I modified the controller adding a method that would generate other methods—the methods that are normally generated when you use scaffolding.

In the end I found that my 3 models were not as close as I had originally thought. The exceptions required to get these techniques to generate all of the code created a lot of complexity that started spilling out to other parts of the system.

Bottom line: these are useful tools to have in your back pocket especially if you are building plugins or other reusable code.
However, they probably should not be used in building a single application due to the additional complexity and non-standard application structure.

Share this article on post this at del.icio.us post this at Digg post this at Reddit

* * *