开发者

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 advantag开发者_运维技巧es and drawbacks of each approach?

Thanks.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜