名称错误:未初始化的常量 - Rails命名空间模块
问题描述:
我有rails应用程序,因为我命名空间需要所有模块。模块没有加载和获取Name error Uninitialised constant Udp
名称错误:未初始化的常量 - Rails命名空间模块
/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
Article.rb
def self.invite
msg = Udp::First.first_ac
msg
end
请帮我解决它。
答
我解决它通过编辑/config/environments/development.rb
如下
config.eager_load = true
因为你的文件夹的Udb(注意最后的b)和你的模块是UDP(注意最后的P)是它不只是?或者是在这个问题上的错字? – Shadwell
我很抱歉。这是一个打字错误。我现在编辑它。 –