I have a simple model called PhoneNumber:
class PhoneNumber < ActiveRecord::Base
validates :pnumber, presence: true, on: :create #=> { :message =>
I had the same error. Turns out in my hasty scaffolding I left out the model.rb file.
Similar with @Michael-Neal.
I had named the controller as singular. app/controllers/product_controller.rb
When I renamed it as plural, error solved. app/controllers/products_controller.rb
If none of the above work, I also have a different approach, as it happened to me in a real scenario.
More specifically using auto-generated Ruby files from Thrift.
In my situation, I had a Module
with several classes, so the order is important in this case:
Class A
makes use of Class B
in the same module. However, Class B
was declared after Class A
.
Simply making Class B
to be declared before Class A
solved the issue to me.
I had a similar error, but it was because I had created a has_one
relationship and subsequently deleted the model that it had_one
of. I just forgot to delete the has_one
relationship from the remaining model.
Some things to try:
Restart the rails console; changes to your models will only get picked up by a rails console that is already open if you do > reload!
(although I have found this to be unpredictable), or by restarting the console.
Is your model file called "phone_number.rb" and is it in "/app/models"?
You should double-check the "--sandbox" option on your rails console command. AFAIK, this prevents changes. Try it without the switch.
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