uninitialized constant ApplicationRecord

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 00:27:08

It appears you're using the Rails 5 tutorial, but working with Rails 4. In Rails 5 all models inherit from ApplicationRecord, while Rails 4 from ActiveRecord::Base

Immediate fix:

class User < ActiveRecord::Base
...
end

Long term fix, switch to Rails 5 and learn with Rails 5

Romeo

Referring to infused's answer from https://stackoverflow.com/a/41388844/5598043

Create a new file called app/models/application_record.rb with the following content:

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true
end

If you are getting this after moving from Rails 5 to Rails 6, ensure you change

config.load_defaults 5.2

for

config.load_defaults 6.0

in your config/application.rb file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!