のActiveRecord :: RecordNotFound PicsControllerで#が示すのRailsでのActiveRecord :: RecordNotFoundエラー
'ID' との写真を見つけることができませんでした= 1
抽出されたソース(ライン#まわり34):
def find_pic
@pic = Pic.find(params[:id])
end
エラーを解決できません。
私のpics_controller.rbは以下の通りです。
class PicsController < ApplicationController
before_action :find_pic, only: [:show, :edit, :update, :destroy]
def index
end
def show
end
def new
@pic = Pic.new
end
def create
@pic = current_user.pics.build(pic_params)
if @pic.save
redirect_to @pic,notice: "Yesss! It was posted!"
else
render 'new'
end
end
private
def pic_params
params.require(:pic).permit(:title, :description)
end
def find_pic
@pic = Pic.find(params[:id]).permit(:title) rescue nil
end
end
マイshow.html.haml
%h1= @pic.title
%p= @pic.description
= link_to "Back", root_path
アップデート:私はrake routes
を実行し、ここで出力されます。
$ rake routes
Prefix Verb URI Pattern Controller#Action
pics GET /pics(.:format) pics#index
POST /pics(.:format) pics#create
new_pic GET /pics/new(.:format) pics#new
edit_pic GET /pics/:id/edit(.:format) pics#edit
pic GET /pics/:id(.:format) pics#show
PATCH /pics/:id(.:format) pics#update
PUT /pics/:id(.:format) pics#update
DELETE /pics/:id(.:format) pics#destroy
root GET / pics#index
pics'テーブル – rony36
'でそこに記録されていませんコンソールを開いてPic.find(1)を試してみると、そのIDのレコードがありますか? – oowowaee
質問に写真を載せないでください。その代わりに、関連するテキストを切り取って貼り付けます。同じ問題を抱えている他の人がこの質問に後で出くわすかもしれませんが、あなたのイメージホストがイメージを削除した場合、質問はもう意味をなさないでしょう。 – MarsAtomic