0
1

More than 3 years have passed since last update.

【Rails】link_toでデータの受け渡しをしたい(途中)

Posted at

やりたいこと

リンクのリクエスト先は同じだが、リンクの押されたページごとに違う処理を行いたい。
そのために、リンクが押された時に、ページ判別用のflagを渡したい。

遷移パターンは以下の通り

  • 一覧(scolor/index)→削除→TOPページ(scolor/index)
  • 詳細(scolor/[:id])→削除→「削除しました」画面(scolor/delete)

実装方法

destroy_pathをルーティングで定義する

【Rails入門説明書】redirect_toについて解説

link_toでidとflagのparamを渡す

<%= link_to "削除", destroy_path_url(id: scholor.id, flag: 0) %>

参考

0
1
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
1