Michael Brooks
Michael Brooks

Reputation: 489

deep nested routes in rails

I have an application where the end goal is to have: a user has lists, a list has items, and a item has attachments. Obviously, I would not think about quad nested lists. Would it be any easier if I did something like this:

resources :users do
  resources :lists 
end

and then

resources :items do
  resources :attachments
end

Could I then create my own routes and links which tie lists to items? Or would I still be facing the same issues when placing links_to's or when creating an attachment would I still need to work through user/id/list/id/item/id?

Upvotes: 0

Views: 180

Answers (1)

Rodrigo Zurek
Rodrigo Zurek

Reputation: 4575

Here is a good article, I have used this strategy ever since I read about it. I would never quad nest anything.

http://rails-bestpractices.com/posts/11-needless-deep-nesting

@post = Post.first
@post.each do |p|
   puts p.favorites
end

Upvotes: 2

Related Questions