3

uninitialized constant Project::Forum::Topic正在

app/controllers/home_controller.rb:46:in `discussions'

我有下面的代码,我正在从 转换rails 2.3.xrails 3.2.11,我认为routes设置有问题。

任何想法我该如何解决?

楷模

class Project < ActiveRecord::Base
      # Relations under project model
      has_many :features, :dependent => :destroy
      has_many :forums, :class_name=>'Forum::Forum'
      has_many :topics, :class_name=>'Forum::Topic', :through=>:forums
class Forum::Forum < Feature
  # Relations under forum model
  has_many :topics, :class_name => 'Forum::Topic', :dependent => :destroy

class Feature < ActiveRecord::Base
  # Relations under feature model
  belongs_to :project

class Forum::Topic < ActiveRecord::Base
   # Relations under topic model
   belongs_to :forum, :foreign_key => :forum_id, :class_name => 'Forum::Forum', :include => :project

home_controller.rb

def discussions
  @project ||= Project.find_by_name 'help'
  @forums = @project.forums
  @topics = @project.topics.recent # HERE I AM GETTING ERRORS
end

路线.rb

scope :home, :controller => "home", :activity => 'read' do
 get :discussions, :path => '/forums', :service_type => 'public'
 get :forums, :action => "discussions"
end

错误

uninitialized constant Project::Forum::Topic
app/controllers/home_controller.rb:46:in `discussions'
4

2 回答 2

2

我刚刚通过rails论坛回答了,再次在这里,

在您的项目模型类中,更改以下方式

老的:has_many :topics, :class_name=>'Forum::Topic', :through=>:forums

新的:has_many :topics, :class_name=>'::Forum::Topic', :through=>:forums

它应该工作

于 2013-03-08T17:54:43.483 回答
0

如果你自动加载那个类(也就是说,你不加载require它的源文件),原因可能是 Ruby 的 bugautoload无法自动加载嵌套 3 次或更多次的常量。

目前,我在互联网上找不到此信息的来源;但是,我记得它应该用 Ruby 2.0 解决,所以你可以修复它,从 删除你需要的文件,在你需要的地方autoload添加一个require 'project/forum/topic',或者升级到 Ruby 2.0。

于 2013-03-07T23:54:52.843 回答