Skip to content
This repository

Trouble with deep nesting under singleton resource #141

Closed
activestylus opened this Issue · 8 comments

5 participants

Douwe Maan Graham Randall Evgeniy Serykh Joel Moss

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

Douwe Maan

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

Douwe Maan

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
Evgeniy Serykh

Yes, it works :+1:

Evgeniy Serykh

After applying this patch controller does not load parent :cry:

Graham Randall

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

Evgeniy Serykh

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

Joel Moss joelmoss closed this
Joel Moss

Fixed in #194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.