小编ken*_*nko的帖子

Rails:在具有警告的子文件夹中组织模型:顶级由B :: A引用的常量A.

今天我决定重新组织大量与用户相关的模型,我遇到了问题.

在我有这样的结构之前:

app/models/user.rb
app/models/user_info.rb
app/models/user_file.rb
...
Run Code Online (Sandbox Code Playgroud)

所以我将所有user_模型移动到用户子文件夹,如下所示:

app/models/user.rb
app/models/user/info.rb
app/models/user/file.rb
...
Run Code Online (Sandbox Code Playgroud)

并将其定义更改为

class User::Info < ActiveRecord::Base
class User::File < ActiveRecord::Base
...
Run Code Online (Sandbox Code Playgroud)

User 模型没有改变(协会除外).

除了User::File模特,一切都很好.当我试图访问此模型时,我收到以下错误:

warning: toplevel constant File referenced by User::File
Run Code Online (Sandbox Code Playgroud)

实际上它返回标准的ruby File类.

我做错了什么?

UPD1:

root# rails c
Loading development environment (Rails 3.2.13)
2.0.0p195 :001 > User::File
(irb):1: warning: toplevel constant File referenced by User::File
 => File
2.0.0p195 :002 > User::Info
 => User::Info(...)
Run Code Online (Sandbox Code Playgroud)

UPD2:

2.0.0p195 :001 > User::SomeModel
NameError: uninitialized constant User::SomeModel
2.0.0p195 :002 > User::IO …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord ruby-on-rails

17
推荐指数
1
解决办法
4103
查看次数

标签 统计

activerecord ×1

ruby ×1

ruby-on-rails ×1