Ruby on Rails 中模型的完全限定名称是什么? [英] What is the fully qualified name of a model in Ruby on Rails?

查看:44
本文介绍了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 包含 FooModuleUser::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.

这篇关于Ruby on Rails 中模型的完全限定名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆