LoginSignup
4
1

More than 1 year has passed since last update.

Rails7で{method: "post"} が GET で認識されるエラー

Posted at

Rails7でデフォルトになったTurboが絡んだ原因であった。
{method: "post"}
ではなく
data: { "turbo-method": :post }
を使う。

リンクのデフォルトのHTTPメソッドはGETだよ。これをGET以外(POST・PUT・PATCH・DELETE)のメソッドに変えるにはdata-turbo-method属性を使うよ。
Turbo Drive|猫でもわかるHotwire入門 Turbo編

before

<%= link_to("削除", "/growth_diaries/#{@growth_diary.id}/destroy", {method: "post"}) %>

after

<%= link_to("削除", "/growth_diaries/#{@growth_diary.id}/destroy", data: { "turbo-method": :post }) %>

参考記事

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