Ruby on Rails 中模型的完全限定名称是什么?
如果我有 2 个不同的类,名称为 User
,在 FooModule
中说一个,在 app/models/user.rb
中说另一个作为模型>,如何确保我使用的是正确的?
If I have 2 different classes with name User
, say one in FooModule
and other as a model in app/models/user.rb
, how do I make sure I am using the correct one?
FooModule::User
肯定会给我正确的.
我想问的是:如果 ApplicationController
包含 FooModule
,User
或 ::User
仍会给我 app/models/user
?
What I had meant to ask was:
If ApplicationController
includes FooModule
, would User
or ::User
still give me app/models/user
?
使用他们的全名,FooModule::User 和 ::User
Refer to them using their full names, FooModule::User and ::User
一般来说,如果你只使用 User,它应该假设你的意思是 ::User,除非你在 FooModule 中.无论哪种方式,请使用 FooModule::User 或 ::User 来确保.
Generally if you just use User, it should assume you mean ::User, unless you are within FooModule. Either way, use FooModule::User or ::User to be sure.