Quick Tip: Route Associations
Are you used to writing your routes like this?
map.resources :notes do |notes|
notes.resource :author
notes.resources :comments
notes.resources :attachments
end
Don’t fret, there may be hope for you yet. For these simple routes you can use the has_one or has_many route association options.
- has_one – use it for a singleton resource
- has_many – use it for plural resources
Refactored routes
map.resources :notes, :has_one => :author, :has_many => [:comments, :attachments]
Give it a try!
Keep in mind I said simple. If you’re doing something more complex they might not be the best choice.
Additional Resources
More of my rantings
These might also interest you
- Caption Contest Fridays #179 (Brainfuel)
- Caption Contest Fridays #98 (Brainfuel)
- Outlook Tip (Brainfuel)







