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 5 years have passed since last update.

【Rails】generateとdbの元に戻し方【Rails Tutorial 3章まとめ】

Last updated at Posted at 2019-11-26

generate

  $ rails generate controller StaticPages home help
  $ rails destroy  controller StaticPages home help

  $ rails generate model User name:string email:string
  $ rails destroy model User

コントローラーの場合、コントローラー名のみでなくアクション名も指定する。
モデルの場合は不要。

db

  $ rails db:migrate
  $ rails db:rollback
  $ rails db:migrate VERSION=0

rollbackで一つ前の状態に戻す。
VERSION=0で最初の状態に戻す。

キャメルケースでコントローラーを生成

$ rails generate controller StaticPages home help
      create  app/controllers/static_pages_controller.rb

コントローラー名をキャメルケースで指定すると、自動でスネークケース(アンダーバーで繋がれた名前)になる。

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?