LoginSignup
0
0

More than 3 years have passed since last update.

rails urlパス変更

Posted at

コントローラー名とは違う命名でルーティングを指定したい!
そんなことが起きた時に使えるコマンドを紹介します。

resourcesとネスト

Railsのルーティング記法の基本は、複数形のresourcesメソッドと単数形のresourceメソッドです。また、Railsのルーティングにはネストを含む多くのオプションがあり、自由度が飛躍的に高まっています。

始めに

スクリーンショット 2021-03-21 15.00.37.png

resources :notifications, only: [:show]

notificationコントローラーのshowアクションにと、ごく普通の記述です。

/notifications/:idの部分を違う名前に変更したいと思い。

pathオプションを使用する。

resources :notifications, only: [:show], :path => "articles" 

スクリーンショット 2021-03-21 15.06.23.png

おわりに

些細なことでも疑問に思った点
解決した点など更新して行きます😁

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