# Quick Tip: Route Associations

> Simplify nested resource routes with has_one and has_many shorthand options

- Author: Curtis Miller
- Published: 2008-08-27
- Categories: rails, how-to
- Canonical URL: https://millarian.com/posts/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

- Module ActionController::Resources (dead link: http://api.rubyonrails.org/classes/ActionController/Resources.html)
