Permalink
Browse files

fix mountable apps namespace issue

  • Loading branch information...
tb committed Jun 29, 2011
1 parent b21aa27 commit f4b2fca2993a0f6b6fc481376a24d36f875ea0d9
Showing with 11 additions and 2 deletions.
  1. +11 −2 lib/inherited_resources/class_methods.rb
@@ -279,15 +279,24 @@ def acts_as_shallow! #:nodoc:
# Initialize resources class accessors and set their default values.
#
def initialize_resources_class_accessors! #:nodoc:
# First priority is the namespaced modek, e.g. User::Group
# First priority is the namespaced model, e.g. User::Group
self.resource_class ||= begin
namespaced_class = self.name.sub(/Controller/, '').singularize
namespaced_class.constantize
rescue NameError
nil
end
# Second priority the camelcased c, i.e. UserGroup
# Second priority is the top namespace model, e.g. EngineName::Article for EngineName::Admin::ArticlesController
self.resource_class ||= begin
namespaced_classes = self.name.sub(/Controller/, '').split('::')
namespaced_class = [namespaced_classes.first, namespaced_classes.last].join('::').singularize
namespaced_class.constantize
rescue NameError
nil
end
# Third priority the camelcased c, i.e. UserGroup
self.resource_class ||= begin
camelcased_class = self.name.sub(/Controller/, '').gsub('::', '').singularize
camelcased_class.constantize

0 comments on commit f4b2fca

Please sign in to comment.