Namespaced models in Rails
"Rails does not scale".
I now have some experience writing software with Rails. I do not believe well written Rails apps would have particular problems to scale up in terms of number of people using the app. Application size, however, seems to be somewhat difficult scale up with Rails. If your app is a bit more complex one, and require lot of model classes, you will likely have problems to keep your app well organized. You might e.g. have hundred classes or fixture files under one directory. You might also have problems with limited namespace and end up using long and ugly looking class names.
Ruby support namespaces and organizing apps using modules. Rails has an assorted support for namespaces. For instance, ActionPack supports namespaces well. On the model side the support has been somewhat vague, but it seems Rails 2.1 and especially the lates Edge Rails support namespaces in ActiveRecord quite well. I don't hear any praise about this great development in the Rails community, but for me, this is great news. Namespaces not only keep me organized and allow sensible class names, they naturally facilitate writing a better architecture and a bit more modular code. There are some workarounds there, but I really think true and complete support for namespaces would indeed be useful.
My personal project is still very much under development, and I use Rails generators lot. And I am using those namespaces in my models. Therefore I decided to tune Rails generators to support namespaces as well. Now I can:
script/generate scaffold Animal::Dog name:string gender:string
This will generate model, controller and views so that you can access them by:
http://localhost:3000/animal/dogs
It also generated working tests and a fixture file, all well orgnized under folders names "animal".
I also changed the naming convention of database names so that namespaced model will be prefixed using the module name (e.g. animal_dog).
I created a ticket to Rails Lighthouse including my patch. I think this is very cool (even hot) stuff, but not seeing too many comments yet. Do give it a try and let me know what you think.
