Home > database >  What is Rails qualified reference mean in Rails Guide?
What is Rails qualified reference mean in Rails Guide?

Time:04-27

enter image description here

It confused me so long when i read this in rails guide, according to this, does the User class below can be loaded?

Because there is no User constant in Admin, so rails assume User is a relative constant,thus the class User can be loaded?It's so confusing

class User
end
module Admin
end
Admin::User # can load User?

CodePudding user response:

No Ruby on Rails would not be able to load Admin::User in your example because Admin::User is not defined in your example.

CodePudding user response:

Until Ruby 2.5 it used to work

Admin::User

Would be loaded since Ruby would look for User under Admin's scope, and then when it couldn't find it - it would keep looking in the top level scope (Object - and there User is indeed defined). But this behavior is deprecated in newer Ruby versions (2.5 ), so no - it won't work.

  • Related