今日、大量のユーザー関連モデルを再編成することにしましたが、問題が発生しています。
私がそのような構造を持つ前に:
app/models/user.rb
app/models/user_info.rb
app/models/user_file.rb
...
したがって、すべてのuser_
モデルを次のようにユーザー サブフォルダーに移動しました。
app/models/user.rb
app/models/user/info.rb
app/models/user/file.rb
...
それらの定義を次のように変更しました
class User::Info < ActiveRecord::Base
class User::File < ActiveRecord::Base
...
User
モデルは変更されませんでした (関連付けを除く)。
User::File
モデル以外はすべて正常に動作します。このモデルにアクセスしようとすると、次のエラーが発生します。
warning: toplevel constant File referenced by User::File
実際、標準の 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(...)
UPD2:
2.0.0p195 :001 > User::SomeModel
NameError: uninitialized constant User::SomeModel
2.0.0p195 :002 > User::IO
(irb):2: warning: toplevel constant IO referenced by User::IO
=> IO
2.0.0p195 :003 > User::Kernel
(irb):3: warning: toplevel constant Kernel referenced by User::Kernel
=> Kernel
私のアプリには、Ruby のデフォルトを除いて、IO またはカーネル クラスがありません。
UPD3:
# app/models/user.rb
class User < ActiveRecord::Base
has_many :files, class_name: 'User::File'
..
end
# app/models/user/file.rb
class User::File < ActiveRecord::Base
belongs_to :user
# some validations, nothing serious
end