Reputation: 461
I recently decided to change the name of a model. So I dropped the DB calling rails db:drop
.
Using sublime text editor I did a find & replace for the model name, and I renamed all relevant directories to be in line with convention; including the migration file etc.
I deleted the schema file.
I called rails db:create
to create the DB: no errors
I called rails db:migrate
to create the tables and schema: no errors.
When I try to call a method on the model class... ('Set')
> Set.all
NoMethodError: undefined method `all' for Set:Class
from (pry):4:in `<main>'
For a test, I ran rails generate model Set
and got the following:
Running via Spring preloader in process 2042
invoke active_record
The name 'Set' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.
So here it seems the model does exist. But it doesn't exist in console.
Upvotes: 0
Views: 44
Reputation: 230561
Why is my model nil
It's not. It's unclear where you drew this conclusion from.
NoMethodError: undefined method `all' for Set:Class
Name of your model (Set
) is the same as class from the standard lib. Due to how rails' autoloading works, name Set is resolved to the stdlib class, not your model. Rename your model with a non-existing name (just as the warning suggests).
Upvotes: 2