【Rails】ルーティングの設定 resources
はじめに
resourcesの名前付きルートがパッと頭に浮かばない時がありましたので、表にまとめました。
resourcesでCRUDのルートを定義する
resourcesはCRUDで必要な7つのルーティングを一括で定義してくれます。
HTTPメソッド | URLパターン | URLパターン名 | ヘルパーメソッド | アクション |
---|---|---|---|---|
GET | /tasks | tasks | tasks_path | index |
GET | /tasks/:id | task | task_path | show |
GET | /tasks/new | new_task | new_task_path | new |
POST | /tasks | tasks | tasks_path | create |
GET | /tasks/:id/edit | task | edit_task_path | edit |
PATCH or PUT | /tasks/:id | task | task_path | update |
DELETE | /tasks/:id | task | task_path | destroy |