1

I am using rails v3.2.2. I have two classes stated like the following:

# app/models/article/category/article_relationship.rb
class Article::Category::ArticleRelationship < ActiveRecord::Base
  ...
end

# app/models/comment/category/article_relationship.rb
class Comment::Category::ArticleRelationship < ActiveRecord::Base
  ...
end

# app/models/article/category.rb
class Article::Category < ActiveRecord::Base
  ...
end

# app/models/article.rb
class Article < ActiveRecord::Base
  ...
end

If in my view file I state

::Article::Category::ArticleRelationship
# or
Article::Category::ArticleRelationship

I get the following error:

NameError
uninitialized constant Category::ArticleRelationship

How can I solve the problem?


UPDATE

I discovered the problem occurs "mostly" when I state at the same time more than one namespaced class in the same file like, for example:

::Article::Category::ArticleRelationship
::Article::Category
# or
::Comment::Category::ArticleRelationship
::Article::Category
# or
::Article::Category
::Article::Category::ArticleRelationship
# or
::Article::Category::ArticleRelationship
Article::Category
# or
Article::Category::ArticleRelationship
::Article::Category
# or
::Article::Category::ArticleRelationship
::Article
# or
::Article
::Comment::Category::ArticleRelationship
# or
...

and it seems to happen randomly!


Note: This question is "inspired" by the answer of @Frederick Cheung to this question.

Community
  • 1
  • 1
Backo
  • 18,291
  • 27
  • 103
  • 170
  • Where are all these classes (ie in which files)? – Frederick Cheung Apr 21 '12 at 02:12
  • @Frederick Cheung - I updated the question with some more information. – Backo Apr 21 '12 at 02:20
  • @Frederick Cheung - I discover some more and I updated the question as well. – Backo Apr 21 '12 at 02:30
  • At first glance I don't see anything obvious wrong with your code, but why are you namespacing your classes three deep? With a parallel structure between articles and comments it seems unlikely that your approach is very DRY. Share a little more about what you're trying to accomplish and maybe we can help you find a better way to do it, thus avoiding your bug by refactoring out of the need to call classes that way. – Andrew Apr 21 '12 at 03:17
  • @Andrew - I am namespacing classes three deep because I need *different* relationships with categories (`Category::ArticleRelationship`) for more than one class that behaves *differently*. *What of important I have to share?* – Backo Apr 21 '12 at 10:50

0 Answers0