While learning Rails Tutorial Chapter 2, "2.3.1 Exploring Microposts", I generated code with scaffold with the wrong column name.
I accidentally typed: one: Micropost as "mivroposts".
$ rails generate scaffold mivroposts content:text user_id:integer
$ rails db:migrate
I noticed a typo only when it was displayed in routes.rb.
Rails.application.routes.draw do resources :mivroposts #What is Maiburo Posutsu? resources :users root 'users#index' end
I searched google for "rails g name mistake" and found an article that describes the procedure for correcting a situation similar to myself, so I used it as a reference. Thank you very much.
: one: I was running
rails db: migrate, so I ran the following command to undo the changes I made to the database.
$ rails db:rollback
$ rails destroy scaffold mivroposts
$ rails generate scaffold Micropost content:text user_id:integer $ rails db:migrate
Rails.application.routes.draw do resources :microposts resources :users root 'users#index' end
== 20200614080432 CreateMicroposts: migrating ================================= -- create_table(:microposts) -> 0.0067s == 20200614080432 CreateMicroposts: migrated (0.0077s) ========================
When I found out that I made a typo, I was surprised and wondered what to do, but at that time I thought it was important to stay calm and avoid making mistakes.
I made a mistake from the beginning of the Rails tutorial and got a little dented, but I thought that there was a lot to learn from the mistake, and it was a good opportunity to learn that it is more important to follow it than to make a mistake. did. (Of course, it's best not to make mistakes, and I can't say such a sweet thing in actual work.)