0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rails generate scaffoldをしたときに打ち間違いをしてしまったらどうするか

Posted at

はじめに

Railsチュートリアル第2章で/usersが開けなかったので、原因を調べたら、scaffoldを作成したときに打ち間違いをしていたためでした。

エラーの原因

rails generate scaffold Usser name:string email:string

Userと打ちたかったところをUsserと打ち間違いをしていますね。

エラー解決までの道のり

打ち間違えに気づいたときには、すでにrails db:migrateを実行していたため、まずは変更を取り消しからはじめました。

rails db:rollback

上記のコマンドを実行すると、以下の表示がターミナルに表示されます。

== 20210123005915 CreateUssers: reverting =====================================
-- drop_table(:ussers)
   -> 0.0047s
== 20210123005915 CreateUssers: reverted (0.0122s) ============================

そして、scaffoldを削除します。

rails destroy scaffold Usser

これでrails generate scaffold Usser name:string email:stringを実行する前まで戻ったはずなので、もう一度rails generate scaffoldをします。今度はうち間違えないように慎重に。

rails generate scaffold User name:string email:string

忘れずにmigrateします。

rails db:migrate
== 20210123041232 CreateUsers: migrating ======================================
-- create_table(:users)
   -> 0.0116s
== 20210123041232 CreateUsers: migrated (0.0129s) =============================

無事に表示されました!

さいごに

打ち間違えって怖いですね。一文字でも違っていればアウトですもんね。
でもまぁ確かに、私の名前は「え"ま"」でも「え"も」でもなく「え"む"」ですもんね。
さて、Usserってなんと読むのでしょう。「ゆーずずずぁー」って感じでしょうか。どうでもええがな。

参考にした記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?