alexandernst alexandernst - 1 year ago 169
Ruby Question

uninitialized constant ApplicationRecord caused by factory girl?

I get

uninitialized constant ApplicationRecord
whenever I try to run
rails db:migrate
and the backtrace seems to be pointing to a spec of
. The exact line that causes the error is

factory :test_user, class: User do

Why is that happening? How is that
isn't defined when that spec is parsed? How can I fix it?

Answer Source

Since Rails 5 a model file application_record.rb with class ApplicationRecord is generated. Every new model should inherit from that class instead of ActiveRecord::Base to prevent mokey patching of ActiveRecord::Base. ApplicationRecord is the new entry point for extensions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download