액티브 :: RecordNotFound PicsController에서 # 보여 레일에 액티브 :: 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