As I get more and more involved in Rails, I keep finding places where it is definitely not DRY. When adding, removing or changing something, I never have complete confidence that I have checked every place where it could be referenced. This is always a sure sign that something is amiss with the framework. The following is kind of a running list of un-DRY thorns that I keep running into while developing Rails applications:
- Migrations: Specify both up AND down.
- Migrations->Validations: Specify column creation in migration and validations.
- Associations: Specify column creation in migration and association in model.
- Validations->View: Specify validations in model and specify which ones are required in the view (red-asterisk problem)
- Migrations/Model->Show view: Specify columns in migration and in the "Show" view.
- Migrations/Model->Index view: Specify columns in migration and in the "Index" view.
- Migrations/Model->Form view: Specify columns in migration and in the "Form" view partial (edit/new).
- Migrations/Model Associations->Show view(s): Specify an association in the migration, in the model, and in the views for BOTH the child AND the parent.
- Model "Human Identifiers": Human-recognizable triggers for a specific record ("Name" for Users, "Title" for books, etc). Specify column in migration and potentially dozens of places in the view and/or helpers.
- Controllers: The vast majority of my controllers are cookie-cutter. Update is almost always find->update_attributes->if no error, redirect to show/if error render edit.
Can anyone think of any others?
The particularly sticky part of this is that these all stack. With an important column you end up having its specification in potentially dozens of places, which is completely unmaintainable. By "Specification" I mean its name, its data type, its associations, its validations, how it is displayed in a show/index, how it is displayed in a form, and search characteristics. Is it possible to keep this all in one place? I'd be satisfied with two places, which is what I'm targeting (migration and "Presenter").
Although there are some existing (and hacky) workarounds to a few of these problems. I look forward to them being solved in a cohesive manner. Specifically, I'm working on #4-10, and my coworker Jordi is working on 1-3. Is there anyone else working on these problems? DataMapper and Merb come to mind, but so far I'm not satisfied that they solve the problems correctly. That doesn't mean we can't learn from them, though.