我们正在对Rails应用程序进行主要数据库更改。为了能够与现有代码互操作,我的计划是在模块命名空间中完成所有工作,以使它们与现有模型分开。但是,我遇到了Rails自动加载问题。
我的文件结构如下:
app/
models/
entity/
new_thing.rb
old_thing.rb
其中new_think.rb包含类似
的内容module Entity
class NewThing
end
end
和old_thing.rb包含类似
的内容class OldThing
end
OldThing
自动加载,但我一直收到这样的错误:
Expected app/models/entity/new_thing.rb to define NewThing
有没有办法可以让它正确地期望entity / new_thing.rb定义Entity::NewThing
?
答案 0 :(得分:0)
尝试:
在你的old_thing.rb
中class OldThing
Extend Entity
end
或
class OldThing
require "entity/new_thing"
end