NameError: uninitialized constant (rails)

后端 未结 10 801
一向
一向 2020-12-24 05:52

I have a simple model called PhoneNumber:

class PhoneNumber < ActiveRecord::Base
  validates :pnumber, presence: true, on: :create #=> { :message =>         


        
10条回答
  •  悲哀的现实
    2020-12-24 06:08

    In my case, I named a column name type and tried to set its value as UNPREPARED. And I got an error message like this:

    Caused by: api_1 | NameError: uninitialized constant UNPREPARED

    In rails, column type is reserved:

    ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'UNPREPARED'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Pl ease rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Food.inheritance_column to use another column for that information

提交回复
热议问题