LoginSignup
0
0

More than 3 years have passed since last update.

routeを設定する際にpathを使えば任意のパスを作れる

Posted at

実装したクラス名とは異なるパスをつけたい

 例えば、hoge_controllerを実装していたが、パスだけhuga/indexにしたい時があったとする。
 こんな時、コントローラー名を変えて、クラス名をいろいろ変えて、、などとする必要はない。routes.rbの設定で何とかなる。(ただし、ファイルの管理はややこしくなってしまうかもしれない。。)

パスだけを任意の形にしたいならpathを使う

  resources :クラス名, path: 実現したいパス do
    collection do
      get :メソッド
    end
  end

もっとカスタムしたい場合は以下を参照

[rails5]routes.rbでprefix・URI・controller#actionの値を任意にカスタマイズできる
https://qiita.com/og3/items/d814bf1a81cce2af633a

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