LoginSignup
0
0

RailsのRESTfulルーティングとパスヘルパー

Posted at

目的

Railsにおけるリソースフルなルーティングとパスヘルパーの確認。

生成されるパスの確認

routes.rb
Rails.application.routes.draw do
  ...
  resources :photos
end
> rails routes
                                  photos GET    /photos(.:format)                                                                                 photos#index
                                         POST   /photos(.:format)                                                                                 photos#create
                               new_photo GET    /photos/new(.:format)                                                                             photos#new
                              edit_photo GET    /photos/:id/edit(.:format)                                                                        photos#edit
                                   photo GET    /photos/:id(.:format)                                                                             photos#show
                                         PATCH  /photos/:id(.:format)                                                                             photos#update
                                         PUT    /photos/:id(.:format)                                                                             photos#update
                                         DELETE /photos/:id(.:format)                                                                             photos#destroy
HTTP verb パス コントローラ#アクション 目的 パスヘルパー
GET /photos photos#index すべての写真の一覧を表示 photos_path
GET /photos/new photos#new 写真を1つ作成するためのHTMLフォームを返す new_photo_path
POST /photos photos#create 写真を1つ作成する photos_path
GET /photos/:id photos#show 特定の写真を表示する photo_path(:id)
GET /photos/:id/edit photos#edit 写真編集用のHTMLフォームを1つ返す edit_photo_path(:id)
PATCH/PUT /photos/:id photos#update 特定の写真を更新する photo_path(:id)
DELETE /photos/:id photos#destroy 特定の写真を削除する photo_path(:id)

参考

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