1

我正在使用导轨 v3.2.2。我有两个类,如下所示:

# 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

如果在我的视图文件中我声明

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

我收到以下错误:

NameError
uninitialized constant Category::ArticleRelationship

我该如何解决这个问题?


更新

当我在同一个文件中同时声明多个命名空间类时,我发现问题“主要”发生,例如:

::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
...

它似乎是随机发生的!


注意:这个问题受到@Frederick Cheung 对这个问题的回答的“启发” 。

4

0 回答 0