削除したいIDをURLにうまく読み込めないです。
エラー分
ActiveRecord::RecordNotFound in OrdersController#destroy
Couldn't find UserFood with 'id'=order:id
def destroy
order = UserFood.find(params[:id])
order.destroy
redirect_to root_path
end
###ターミナル
Prefix Verb URI Pattern Controller#Action root GET / orders#index orders GET /orders(.:format) orders#index POST /orders(.:format) orders#create new_order GET /orders/new(.:format) orders#new order DELETE /orders/:id(.:format) orders#destroy
###orders.controller.rb
ruby
1def destroy 2 order = UserFood.find(params[:id]) ←こちら 3 order.destroy 4 redirect_to root_path 5end
###index.html.haml
.right-bar .order-list - @user_foods.each do |user_food| .order-box .order-box__deta .order-box__deta--name = user_food.food .order-box__deta--number = user_food.quantity .order-box__deta--delete = link_to '消', '/orders/order:id', method: :delete ←こちら
order = UserFood.find(params[:id])
ここでparamsの中身を確認したのですがid = order:idのような記述になっておりテーブルからデータをうまく引き出せないです。
他で似たようなエラーのサイトを拝見してhamlの記述を変えたりもしてみたのですが解決できないです。
下のような記述でもうまくいかない
ruby
1#orders.controller.rb 2 def destroy 3 @order = UserFood.find(params[:id]) 4 @order.destroy 5 redirect_to root_path 6 end
haml
1#index.html.haml 2.right-bar 3 .order-list 4 - @user_foods.each do |user_food| 5 .order-box 6 .order-box__deta 7 .order-box__deta--name 8 = user_food.food 9 .order-box__deta--number 10 = user_food.quantity 11 .order-box__deta--delete 12 = link_to "消", order_path(order), method: :delete
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/13 05:23
2020/05/13 08:28
2020/05/13 09:05 編集
2020/05/13 09:05
2020/05/13 09:16