LoginSignup
7
6

More than 5 years have passed since last update.

ルーティングで使用するパラメータ名を変更

Posted at

ルーティングで使われるパラメータを変更したかった要望があったのでメモ

resource :idea

     idea POST   /idea(.:format)                ideas#create
 new_idea GET    /idea/new(.:format)            ideas#new
edit_idea GET    /idea/:id/edit(.:format)           ideas#edit
          GET    /idea/:id(.:format)                ideas#show
          PATCH  /idea/:id(.:format)                ideas#update
          PUT    /idea/:id(.:format)                ideas#update
          DELETE /idea/:id(.:format)                ideas#destroy

:param オプションを使用してresourceを唱えるとパラメータ名を変更できる

resource :idea, :param => 'not_id'
      idea POST   /idea(.:format)               ideas#create
  new_idea GET    /idea/new(.:format)           ideas#new
 edit_idea GET    /idea/:not_id/edit(.:format)          ideas#edit
           GET    /idea/:not_id(.:format)               ideas#show 
           PATCH  /idea/:not_id(.:format)               ideas#update
           PUT    /idea/:not_id(.:format)               ideas#update
           DELETE /idea/:not_id(.:format)               ideas#destroy

参考
Change the name of the :id parameter in Routing resources for Rails

7
6
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
7
6