Tomoko Yamaguchi
Tomoko Yamaguchi

Reputation: 497

Should routes be nested for associations?

I have a one-to-many association between User and Occupation (a user has_many :occupations). In the routes file, I did:

resources :users do 
   resources :occupations 
end 

to nest the occupations routes inside the users. Playing around with AJAX requests, I realized it's easier for me to not have the occupations route nested, like this:

resources :users

resources :occupations 

My question is, do I lose (performance, functionality) in any way by not having the routes nested?

Update: Aside from losing the users/1/occupations routing. I know that I won't get that if I don't nest the routes.

Upvotes: 2

Views: 57

Answers (1)

Dan Wich
Dan Wich

Reputation: 4943

I wouldn't worry about the performance (if anything, the nested routes might be slightly slower) and just design the routes that make the most sense for your application.

Upvotes: 1

Related Questions