I have a simple model called PhoneNumber:
class PhoneNumber < ActiveRecord::Base
validates :pnumber, presence: true, on: :create #=> { :message =>
I ran into this also with a file directly in the models
directory, and it turns out that I wasn't properly loading up the code on startup. I was able to fix the issue by setting config.eager_load = true
in my development.rb file. This made the class available to me in the console
I was getting the error:
NameError: uninitialized constant
Then I noticed that I had accidentally created a plural model so I went back and renamed the model file to singular and also changed the class name in the model file to singular and that solved it.
I had this problem because I changed the name of the class in a model, and it did not match the name of the file.
"Model class names use CamelCase. These are singular, and will map automatically to the plural database table name.
Model files go in app/models/#{singular_model_name}.rb."
https://gist.github.com/iangreenleaf/b206d09c587e8fc6399e#model
I started having this issue after upgrading from Rails 5.1 to 5.2
It got solved with:
spring stop
spring binstub --all
spring start
rails s