Nested Routes Rails precautions

Learning with Earning

Resources should never be nested more than 1 level deep.

These multi-level nested routes is violation of above mentioned rule.

resources :hotels do
  resources :food_menus do
   resources :categories do
     resources :dishes

My Questions about Rails Guide Recommendation:
1. Why it is recommended to use 1 Level Deep routes?

2. Why they are saying not to enjoy Rails Nested Routes?

3. Is there any problem or overhead there?

4. One Level Nesting would cause multiple generation of a resource routes
    a. One as Nested
    b. Other as Non Nested

5. So On… 🙂

Answer to Q# 1,2,3 is:
If you use more than 1 level deep nesting then,

1. You need to pass object of each resource in helper

2. Rails will generate very very long Routes Helper & Url.

Show Method Url & Helper of dishes:

hotel_food_menu_category_dish_path(@hotel_object, @food_menu_object, @categor_object, @dish_object )

3. Yes, It…

View original post 74 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s