前提・実現したいこと
現在railsで、在庫管理のサイトを作成しておりまして編集機能をつけて編集をできるようにしようとしているのですが機能がうまく反応せずにエラーになっています
発生している問題・エラーメッセージ
ActiveRecord::RecordNotFound in ItemsController#update Couldn't find Item with 'id'=edit Extracted source (around line #31): 29 30 31 32 33 34 def update @item = Item.find(params[:id]) @item.update(item_params) redirect_to root_path end Rails.root: /Users/yukihiro/stock Application Trace | Framework Trace | Full Trace app/controllers/items_controller.rb:31:in `update' Request Parameters: {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"EyDppYB3jJCZgj+uoZh4MgaAWy0HFtV8XR8zvZjujdh4PvA7OwcXdfUpHdH+g/lYqsqzmFuhT77bcUGc1/8iZg==", "item"=>{"name"=>"mo", "capacity"=>"342", "until"=>"kg", "quantity"=>"45個", "place"=>"1番冷蔵庫", "deliverydate"=>"5月25日"}, "commit"=>"変更する", "id"=>"edit"}
該当のソースコード
rails
1class ItemsController < ApplicationController 2 def index 3 @items = Item.all 4 end 5 6 def new 7 @item = Item.new 8 end 9 10 def create 11 @item = Item.new(item_params) 12 if @item.save 13 redirect_to root_path 14 else 15 render :new 16 end 17 end 18 19 20 def destroy 21 item = Item.find(params[:id]) 22 item.destroy 23 redirect_to root_path 24 end 25 26 def edit 27 @item = Item.find(params[:id]) 28 end 29 30 def update 31 @item = Item.find(params[:id]) 32 @item.update(item_params) 33 redirect_to root_path 34 end 35 36 37 private 38 def item_params 39 params.permit(:name, :capacity, :until, :quantity, :place, :deliverydate) 40 # params.require(:item).permit(:name, :capacity, :until, :quantity, :place, :deliverydate) 41 end 42 43end
= form_with(url: "/items/edit",model: @item, local: true )do |f| .edit .edit_header .edit_header_name =link_to "NETASTOCKS",root_path,class:'neta' .edit_main .edit_main_title 在庫編集 .edit_main_box .edit_main_box_text .box .box_box = link_to '削除', "/items/#{@item.id}", method: :delete,class: "destroy" .form_text .field %label 材料名 = f.text_field :name,class: 'text' .field %label 容量 = f.number_field :capacity,class: 'text' .field %label 単位 = f.select :until,[ ["g","g"], ["kg", "kg"],["t","t"], ["個", "個"],["パック","パック"], ["枚", "枚"]], prompt: "---" .field %label 個数 = f.text_field :quantity,class: 'text' .field %label 場所 = f.select :place,[ ["プレハブ","プレハブ"], ["リーチイン", "リーチイン"], ["1番冷蔵庫", "1番冷蔵庫"], ["2番冷蔵庫", "2番冷蔵庫"], ["3番冷蔵庫", "3番冷蔵庫"], ["1番冷凍庫", "1番冷凍庫"], ["2番冷凍庫", "2番冷凍庫"] , ["切りネタ冷凍庫", "切りネタ冷凍庫"], ["ハマチ倉庫", "ハマチ倉庫"], ["ネタ切り冷蔵庫", "ネタ切り冷蔵庫"]], prompt: "---" .field %label 納品日 = f.text_field :deliverydate,class: 'text' .form_text_btn = f.submit '変更する',class: :form__btn
Rails.application.routes.draw do root to: "items#index" resources :items, only: [:index, :new,:edit,:destroy,:update]do collection do post 'create', to: 'items#create' end end end
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。