Permalink
Browse files

do not overwrite class_attribute :resource_class defined in controller

  • Loading branch information...
tb committed Jun 24, 2011
1 parent 7870f02 commit b21aa27b218aa831592a449e554a2361bfc39d6f
Showing with 3 additions and 2 deletions.
  1. +2 −1 app/controllers/inherited_resources/base.rb
  2. +1 −1 lib/inherited_resources/class_methods.rb
@@ -30,7 +30,8 @@ def self.inherit_resources(base)
:parent_url, :parent_path,
:smart_resource_url, :smart_collection_url
self.class_attribute :resource_class, :parents_symbols, :resources_configuration, :instance_writer => false
self.class_attribute :resource_class unless self.respond_to? :resource_class
self.class_attribute :parents_symbols, :resources_configuration, :instance_writer => false
protected :resource_class, :parents_symbols, :resources_configuration,
:resource_class?, :parents_symbols?, :resources_configuration?
@@ -280,7 +280,7 @@ def acts_as_shallow! #:nodoc:
#
def initialize_resources_class_accessors! #:nodoc:
# First priority is the namespaced modek, e.g. User::Group
self.resource_class = begin
self.resource_class ||= begin
namespaced_class = self.name.sub(/Controller/, '').singularize
namespaced_class.constantize
rescue NameError

3 comments on commit b21aa27

@andersondias

This comment has been minimized.

Show comment
Hide comment
@andersondias

andersondias Oct 17, 2011

This commit created a bug in my code. I have an InheritedResources::Custom class that extends InheritedResources::Base. The problem is that this code does not respect this kind of inheritance and my resource_class is returning InheritedResources::Custom. Is it an undesirable behavior?

andersondias replied Oct 17, 2011

This commit created a bug in my code. I have an InheritedResources::Custom class that extends InheritedResources::Base. The problem is that this code does not respect this kind of inheritance and my resource_class is returning InheritedResources::Custom. Is it an undesirable behavior?

@josevalim

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Oct 17, 2011

Contributor

You should be able to easily fix this issue by setting self.resource_class back to nil in your custom controller.

Contributor

josevalim replied Oct 17, 2011

You should be able to easily fix this issue by setting self.resource_class back to nil in your custom controller.

@tardate

This comment has been minimized.

Show comment
Hide comment
@tardate

tardate Oct 17, 2012

This also breaks the ability to subclass inherited resources controllers
e.g. I have an Api::BaseController that includes IR, and resource-specific controllers like Api::UsersController < Api::BaseController

After this change the Api::UsersController thinks that it's resource class is Api (the self.resource_class = nil trick doesn't work in this case).

I am using a fork which restores the sub-classing behaviour and supports it with tests (see evendis@799747f). Before I think about sending a pull request, I wanted to find out why this change was necessary:

  • there aren't any tests to set the expectations (all tests pass with or without these changes)
  • isn't the ability to override :resource_class in defaults enough? I haven't come across a need to override the resource_class implementation itself before

tardate replied Oct 17, 2012

This also breaks the ability to subclass inherited resources controllers
e.g. I have an Api::BaseController that includes IR, and resource-specific controllers like Api::UsersController < Api::BaseController

After this change the Api::UsersController thinks that it's resource class is Api (the self.resource_class = nil trick doesn't work in this case).

I am using a fork which restores the sub-classing behaviour and supports it with tests (see evendis@799747f). Before I think about sending a pull request, I wanted to find out why this change was necessary:

  • there aren't any tests to set the expectations (all tests pass with or without these changes)
  • isn't the ability to override :resource_class in defaults enough? I haven't come across a need to override the resource_class implementation itself before
Please sign in to comment.