Vinay
Vinay

Reputation: 61

Avoiding too much nesting in Ruby on Rails Resources

I have a resource Offering which has_many Allocations. Each Allocation belongs_to Account. I want to be able to go to /offering/1/account/2/allocations (that is, list all Allocations for Offering 1 and Account 2) or something similar, but I don't want to break the rule that "resources should never be nested more than 1 level deep."

I only need the "index" action on allocations (when doing /offering/1/account/2.) What's the best way to do this? I am not particular about the URL or even necessarily keeping the "index" action in the Allocation controller.

Thanks!

Upvotes: 1

Views: 159

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107728

Not so much of a rule as a guideline.

There are some cases which you can break it and I think this is just fine. For the show action of an account you can show the allocations and then you'll have the /offering/1/account/2/ URL.

Upvotes: 1

Related Questions