uninitialized constant ApplicationRecord error

前端 未结 2 1458
庸人自扰
庸人自扰 2021-01-16 22:12

I am following the RailsTutorial and have been creating a Users model with appropriate attrs and validations. I\'ve run into this error and cannot see where the problem is.

相关标签:
2条回答
  • 2021-01-16 22:40

    Turns out I had by mistake checked out from the brand where the migrations and models were created, back into master branch where these migrations and models were not present. Without those models present neither was the application_record.rb file thus the error of uninitialized constant ApplicationRecord.

    0 讨论(0)
  • 2021-01-16 22:53

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

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

    Explanation: When generating a new Rails 5+ project the application_record.rb file will be created automatically, but if using a project that was generated on an earlier version and upgraded to 5+ you need to create this file yourself.

    0 讨论(0)
提交回复
热议问题