ActiveRecord::RecordNotFound in TopController#entry
Couldn't find Product with 'id'=
とエラーが出ました。
top_controller.rbには
Ruby
1class TopController < ApplicationController 2 3 def entry 4 @product = Product.find(params[:id]) 5 end 6 7 def post 8 Review.create(nickname:current_user.nickname, product_id:params[:id], rate:create_params[:rate], review:create_params[:review]) 9 redirect_to action: :index 10 end 11 12end
と記載し、
modelsのproduct.rbには
Ruby
1class Product < ActiveRecord::Base 2 has_many :reviews 3end
と記載し、
routes.rbには
Ruby
1TechReviewSite::Application.routes.draw do 2 3 root 'products#index' 4 get '/product/:id' => 'products#show' 5 get '/search/' => 'top#search' 6 get'/entry/:id' => 'top#entry' 7 post'/entry/:product_id' => 'top#post' 8 get '/product/:id/reviews/new' => 'reviews#new' 9 get 'products/search' => 'top#entry' 10 11 end
と記載しました。
idが空、という事ですが、データベースにはすでにidが入っており、なぜnil
と表示されるのかわかりません。
マイグレーションでカラムの追加をしたほうがよいのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。