実現したいこと
https://techtechmedia.com/favorite-function-rails/
こちらを参考にいいね機能の実装をしてます。
発生している問題・エラーメッセージ
method: :postとしているのにgetで処理されてしまう為Routing Errorとなってしまう
エラーメッセージ
ActionController::RoutingError (No route matches [GET] "/like/5"):
該当のソースコード
slim
1- if current_user.liked_by?(@spot.id) 2 td 3 = link_to destroy_like_path(@spot), class: "like-link", method: :delete, remote: true do 4 i.fa.fa-heart.unlike-btn 5 = @spot.likes.count 6- else 7 td 8 = link_to create_like_path(@spot), class: "like-link", method: :post, remote: true do 9 i.fa.fa-heart.like-btn 10 = @spot.likes.count
試したこと
https://blog.ezic.info/43631.html
rails-ujs は読み込んでました。
ルーティングも確認しましたが、問題はなさそうです。
検証ツールでも確認してみましたがdata-method="post"となってました。
methodを{}で囲ってみたりもしましたが変わりませんでした。
補足情報(FW/ツールのバージョンなど)
ruby 3.0.2p107
rails (~> 6.1.4)
GitHub
https://github.com/Ryo0116/Saitamap
よろしくお願いいたします。
