Trouble with deep nesting under singleton resource #141

activestylus opened this Issue May 14, 2011 · 8 comments

5 participants


Given the following:

# models
Site has_one :theme
Theme has_many :templates

# routes
resources :sites do
  resource :theme do
    resources :templates

# controller
nested_belongs_to :site do
  nested_belongs_to :theme

When I try to visit site/:site_id/theme/templates/:id

undefined method `themes' for #<Site:0x00000106106da8>

Not sure why it's assuming a has_many on that relationship.
I've tried using the singleton flag in two different ways:

nested_belongs_to :site, :singleton => true do
  nested_belongs_to :theme

nested_belongs_to :site do
  nested_belongs_to :theme, :singleton => true

But there is no change. Am I doing this wrong or have I stumbled onto a fringe case outside the intended use of the gem?

FWIW I'm on Rails 3.0.7 and Ruby 1.9.2-p180 using inherited_resources 1.2.2


I'm having the same problem -- has anyone found a solution since May?


Got this to work, and submitted it as pull request #194.

Your code should work as

class TemplatesController < InheritedResources::Base
  belongs_to :site do
    belongs_to :theme, :singleton => true

Yes, it works 👍


After applying this patch controller does not load parent 😢


FWIW, I'm using the patch with CanCan and load_and_authorize_resource for each of the parents in the hierarchy without problem.


Oops, I was inattentive (forgave to write :singleton => true in defaults macros).
Cool patch, bro 🆒


Fixed in #194

@joelmoss joelmoss closed this Mar 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment