LoginSignup
0

More than 1 year has passed since last update.

【Rails】コントローラ作成方法メモ

Posted at

0. 環境

macOS Monterey 12.3.1
ruby 3.1.2
rails 6.1.6

1. コントローラ作成方法

以下のコマンドを入力する。

ターミナル
rails g controller (コントローラ名) (アクション名1) (アクション名2)...

作成例

ターミナル
rails g controller users index show

2. 特定のディレクトリ下に作成する時

コントローラ名にパスを付けて入力する。

ターミナル
rails g controller api/v1/users index show

または

ターミナル
rails g controller api::v1::users index show

3. 作成コマンドを取り消したい時

g(generate)destroyに置き換える。

ターミナル
rails destroy controller users index show

参考記事

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