Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?