LoginSignup
0
0

More than 5 years have passed since last update.

ルーティングについて

Last updated at Posted at 2016-12-18

ルーティングについての備忘

以下は同じ
memo_path(memo)
"/memos/#{memo.id}"

rake routeで実行することでPrefixを確認できる

route
Prefix Verb   URI Pattern          Controller#Action
  root GET    /                    memos#index
 memos POST   /memos(.:format)     memos#create
  memo DELETE /memos/:id(.:format) memos#destroy

例えば、memos#destroyに対応するパスに「memo」というPrefixが付与されていることがわかります。
link_toの第二引数を(Prefix名)_pathとすると、そのPrefixに対応するパスをリンク先として指定することができます。

destroyのように、パラメータとしてidが必要になる場合、(Prefix名)_pathの後に括弧をつけて、そのインスタンスを渡します。

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