Swanand
Swanand

Reputation: 12426

What is the fully qualified name of a model in Ruby on Rails?

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?

EDIT: FooModule::User would definitely give me the correct one.

What I had meant to ask was: If ApplicationController includes FooModule, would User or ::User still give me app/models/user?

Upvotes: 2

Views: 1598

Answers (1)

Steven Soroka
Steven Soroka

Reputation: 19902

Refer to them using their full names, FooModule::User and ::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.

Upvotes: 9

Related Questions