ActiveRecord: Pass class instead of string to class_name when defining associations
activerecord, associations, ruby-on-rails
Solution
The class may not be loaded yet in which case you'll get a `NameError: uninitialized constant User`.
You're supposed to use `"User"` for this reason, as implied by the option name: `:class_name`, not `:class`.
Problem
Are there any implications or gotchas to passing in a class instead of a string when defining an association? ``` belongs_to :owner, class_name: User ``` As opposed to: ``` belongs_to :owner, class_name: "User" ```