5
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 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 }) %>

参考記事

5
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
5
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?