16
15

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 5 years have passed since last update.

Railsのlink_toでparamsを飛ばす方法

Last updated at Posted at 2019-07-18

#やりたいこと
リンクのリクエスト先は同じだが、
リンクの押されたページごとに違う処理を行いたい。

そのために、リンクが押された時に、ページ判別用のフラッグをたてたい。

#実装方法

.rb
= link_to hoge_path(:key => "value")

= link_to hoge_path(key: "value")

上記の通り、リンク先のpathの後に、送りたいparamsのキーとバリューを記載することで、
飛び先のアクション内で値を取得できる

.rb
params[:key]
-> "value"
16
15
2

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
16
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?