alste
alste

Reputation: 1455

Rails: Nesting resources more than 1 level deep

In my app, Users have many Conversations, and Conversations have many Messages. I logically structured my resources as follows:

  resources :users do
    resources :conversations do
      resources :messages
    end
  end

To me, this is a logical structure. But it is advised to never nest resources more than 1 level deep.

So, should I make Conversations an independent resource or just go ahead and break the guideline? What are the global advantages and drawbacks of each approach?

Thanks.

Upvotes: 4

Views: 1058

Answers (2)

Anatoly
Anatoly

Reputation: 15530

the only advice is what the meet business requirements. if you need to have 2 deep level, just try how it works with using :shallow=>true. but sure, it's rarely to use more than 1 deep level on practice

Upvotes: 0

August Lilleaas
August Lilleaas

Reputation: 54603

But it is advised to never nest resources more than 1 level deep.

I think you can safely disregard that "advice". You can nest them as much as you want. I frequently nest 3 and 4 levels deep in my apps.

Upvotes: 5

Related Questions