【发布时间】:2016-02-15 14:34:17
【问题描述】:
我有 Rails 应用程序,其中我已命名所有必需的模块。模块未加载并获取 Name error Uninitialised constant Udp
/app/adapters/Udp/ #Here Udp is the module name
包含两个文件。
first.rb
module Udp
class First #First is the class name
def self.first_ac
"first"
end
end
end
sec.rb
module Udp
class Sec
def self.sec_ac
"sec"
end
end
end
config/application.rb
config.autoload_paths += Dir["#{config.root}/app/adapters/**/*"]
我正在尝试访问: Articles_controller
def index
msg = Article.invite
render text: msg
end
文章.rb
def self.invite
msg = Udp::First.first_ac
msg
end
请帮我解决。
【问题讨论】:
-
这不仅仅是因为你的文件夹是 Udb(注意末尾的 b)而你的模块是 Udp(注意末尾的 p)是吗?还是问题中的错字?
-
对不起。这是一个打字错误。我现在已经编辑了。
标签: ruby-on-rails ruby uninitialized-constant