에서 업데이트 아무런 ID 에러 코드 조각 없다 (= 1), 파라미터 덤프제어기 여기
Couldn't find Category without an ID
그러나 거기 카테고리 ID :
def update
@category = Category.find(params[:id])
if @category.update_attributes(params[:category], :as => :roles_update)
@category = Category.find[params[:id]]
render 'show', :notice => 'Category was successfully updated'
else
@categories = Category.all
render 'index'
end
end
오류 상기 실행시 :
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"aFk+bcHKA3zwck1PgrNOwVvZfeXtsT57ywHGiB4odDY=",
"category"=>{"description"=>"audio/video",
"active"=>"1"},
"commit"=>"Update Category",
"id"=>"1"}
코드는 오류 없을 것입니다 경우 주석으로 #을 @ 카테고리 = Category.find [PARAMS [: 아이디] IF 루프한다. 그러나 rspect는 오류를 발생시킵니다. ActiveRecord :: RecordNotFound :
문제에 대한 제안 사항이 있습니까? 감사합니다
이 줄 수 있습니다. 둥근 괄호를 사용해야합니다 :'@category = Category.find (params [: id])'. – Alex
대괄호는 확실히 문제가 될 것입니다. @category = Category.find (params [: id])'(라인 5)보다는 @ @ category.reload를 쓰면 코드를 단순화 할 수 있습니다. (라인 5) –
nil.reload 오류가 발생했습니다. "평가하는 동안 오류가 발생했습니다 nil.reload ". 편집 방법은 다음과 같습니다. def edit @category = Category.find (params [: id]) end – user938363