Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 未初始化的常量Model1::Model2::Model3_Ruby_Ruby On Rails 3_Ruby On Rails 3.2 - Fatal编程技术网

Ruby 未初始化的常量Model1::Model2::Model3

Ruby 未初始化的常量Model1::Model2::Model3,ruby,ruby-on-rails-3,ruby-on-rails-3.2,Ruby,Ruby On Rails 3,Ruby On Rails 3.2,我正在获取未初始化的常量项目::论坛::主题 app/controllers/home_controller.rb:46:in `discussions' 我有下面的代码,我正在从rails 2.3.x转换到rails 3.2.11,我认为路由设置有问题 知道我该怎么修吗 型号 class Project < ActiveRecord::Base # Relations under project model has_many :features, :depend

我正在获取未初始化的常量项目::论坛::主题

app/controllers/home_controller.rb:46:in `discussions'
我有下面的代码,我正在从
rails 2.3.x
转换到
rails 3.2.11
,我认为
路由设置有问题

知道我该怎么修吗

型号

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
uninitialized constant Project::Forum::Topic
app/controllers/home_controller.rb:46:in `discussions'
routes.rb

def discussions
  @project ||= Project.find_by_name 'help'
  @forums = @project.forums
  @topics = @project.topics.recent # HERE I AM GETTING ERRORS
end
scope :home, :controller => "home", :activity => 'read' do
 get :discussions, :path => '/forums', :service_type => 'public'
 get :forums, :action => "discussions"
end
错误

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
uninitialized constant Project::Forum::Topic
app/controllers/home_controller.rb:46:in `discussions'

如果您自动加载该类(也就是说,您不需要
它的源文件),那么原因可能是Ruby
自动加载
的错误,无法自动加载嵌套的常量3次或更多次


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

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

旧:
有很多:主题,:class\u name=>'Forum::Topic',:through=>:forums

新:
有很多:主题,:class\u name=>'::Forum::Topic',:through=>:forums


它应该可以工作

您可以包括这些类在哪些文件中定义吗?我注意到您还缺少类名称之前的
类调用。代码真的是这样吗?@RyanBigg,更新了我的问题我没听清楚,我使用的是Rails 3.2。xRails不属于我的问题,它是Ruby问题;您如何调用定义
项目
论坛
主题
的文件?它们所在的文件夹结构是什么?