Are there any consequences or gotchas for passing in a class instead of a string when defining an association?
belongs_to :owner, class_name: User
Unlike:
belongs_to :owner, class_name: "User"
The class may not load, but in this case you will get NameError: uninitialized constant User .
NameError: uninitialized constant User
You should use "User" for this reason, as implied by the option name :class_name , not :class .
"User"
:class_name
:class
In rare cases, I encounter some random errors when using classes (User) instead of the class name as a string ("User"). I cannot reproduce them and solve this by simply restarting the application server.
It can be a symbol. It cannot be a class constant, because if you have two connected models, when the first loads, the second is not defined yet, so the constant will not be defined, and this will lead to an error.
Source: https://github.com/rails/rails/issues/6486
Source: https://habr.com/ru/post/959359/More articles:How do I enable the RSA public key in Google Play Services in my binary Android application? - androidHow to submit multi-part / form data to upload files using SpringMVC and MockMVC - javaspaces between data lines are displayed when using SPOOL in SQLPlus - oracleYii pagination shows fewer items than available - phpreading an entire text file with vba - vbaInput end of VBA excel file - vbaJavascript callback function in a separate thread - javascriptXLDateFree workaround - pythonIncorrect index scanning in Postgres in multiple field conditions? - indexingRecursive - Verbose in Powershell - powershellAll Articles