Ran into my first challenge with the blogger today. I was creating a new model for a Comment feature and I typed:
$ bin/rails generate model Comment author_name:string body:text articles:references
$ bin/rails generate model Comment author_name:string body:text articles:references
That single red letter cost me an hour of struggle (I mean 'learning'). The extra s created a database schema containing something called 'articles_id'.
Since id is a property of a single article, the comment controller couldn't find an id for articles, as it didn't exist.
I looked at the Comment model file and saw the extra s almost immediately after trying to enter a comment. But then I couldn't reverse the error.
Rolling back the migration (rake db:rollback), had no effect on the schema.
Destroying the model (rails destroy model Comment) had no effect on the schema.
In the end I replaced the my local files with the Github repo contents (luckily I had just done a push).
git fetch --all
git reset --hard origin/master
THEN, I recreated the correct model, ran the migration and reset the database
(rake db:reset).
Unfortunately, this meant I lost the five beautifully written articles I had stored in the first database. Perhaps I didn't need that db:reset?
Comments
Post a Comment