Namespaces: undefined method `all' for Api:Module #204

Closed
coneybeare opened this Issue Feb 1, 2012 · 3 comments

Projects

None yet

3 participants

@coneybeare

I have some namespaced controllers that live inapp/controllers/api/ and each are subclasses of an ApiController. This ApiController is a subclass of InheritedResources::Base.

When attempting to get the index on one of the Api::FooController subclasses, I get this error:

undefined method `all' for Api:Module

with this backtrace:

inherited_resources (1.3.0) lib/inherited_resources/base_helpers.rb:25:in `collection'
inherited_resources (1.3.0) lib/inherited_resources/actions.rb:7:in `index'
…

Changing the Api::FooController subclass to InheritedResources::Base allows it to work, but doesn't pull in my ApiController superclass that I need it to. Can inherited_resources be used if the controller is not a direct subclass of InheritedResources::Base?

@coneybeare

I have found that making my ApiController superclass back into an ApplicationController subclass, then adding inherit_resources to the Api::FooControllers cases it to work. Is this the solution to the problem, or just a workaround?

@gevans
gevans commented Aug 7, 2012

I noticed that extending a controller within the same module seems to fix the problem as well. Creating an Api::BaseController with inherit_resources and extending it for controllers in that namespace/module DRYs it up a little.

@joelmoss

There are a couple of solutions here (see above) so there is nothing more needed here. thx

@joelmoss joelmoss closed this Dec 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment