R6Sというゲームの戦績管理サイトを作っているときに、急にdeleteメソッドが使えなくなり,logを見たところ、deleteの代わりにGetが送信されていました。
ググって調べたところ、<%= link_to %>タグではなく、<%= button_to >にすれば、deleteが送信されるということだったので、試したらルーティング周りの問題は解決したっぽいのですが、また新たにストロングパラメータの箇所で
param is missing or the value is empty: result
というエラーが発生。
エラー箇所
def result_params params.require(:result).permit(:date, :map, :opponent, :MYround, :OPround) end
resultが空なのかな...?と思い、バリデーションを追加するも、解決に至りませんでした。
私はどこにエラーがあるのか見当もつかないため、もしほしいページや情報がありましたら追記いたします。
index.htnl.erb
html.erb
1 <tbody> 2 <% @results.each do |result|%> 3 <tr> 4 <th><%= result.date %></th> 5 <th><%= result.map %></th> 6 <th><%= result.MYround %> vs <%= result.OPround %></th> 7 <th><%= link_to '詳細', result %></th> 8 <th><%= button_to "削除する", method: :delete, data: {confirm: "削除しますか?"} %></th> 9 </tr> 10 <% end %> 11 </tbody>
routes.rb
ruby
1Rails.application.routes.draw do 2 resources :results 3 root "results#index" 4end
ここが参考になりませんか?
https://teratail.com/questions/82506
ありがとうございます
以前その投稿も見たのですが、私の場合、パラメータの値が
{"authenticity_token"=>"3YVKUT/Fbs2DTVVWnItV+4gG36wlBcselC1UPqHqFPJ/4T9V6/Uo3KA/QuOassurPesiRNo9y6EH6kVBT7qcrw==", "data"=>{"confirm"=>"削除しますか?"}, "method"=>"delete"}
となっており、Viewの方もform_forでしっかり記述しているので、解決には至りませんでした。
あなたの回答
tips
プレビュー