Trouble with deep nesting under singleton resource #141

Closed
activestylus opened this Issue May 14, 2011 · 8 comments

5 participants

@activestylus

Given the following:

# models
Site has_one :theme
Theme has_many :templates

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

# controller
inherit_resources
nested_belongs_to :site do
  nested_belongs_to :theme
end

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
end

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

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

@DouweM

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

@DouweM

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
  end
end
@evserykh

Yes, it works 👍

@evserykh

After applying this patch controller does not load parent 😢

@grandall

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

@evserykh

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

@joelmoss

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