업데이트 작업에서 Nomethoderror가 발생합니다
-
19-09-2019 - |
문제
이것은 내 소스 코드입니다
def update
@recipe = Recipe.find(params[:id])
respond_to do |format|
if @recipe.update_attributes(params[:recipe])
format.html {redirect_to :action => "edit" }
end
end
end
이 줄에 오류가 발생합니다
respond_to do |format|
오류 메시지는 "예상하지 못한 경우 NIL 객체가 있습니다. NIL.CALL을 평가하는 동안 오류가 발생했습니다"입니다.
스택 추적의 5 줄은 다음과 같습니다.
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/mime_responds.rb:175:in `respond'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/mime_responds.rb:173:in `each'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/mime_responds.rb:173:in `respond'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/mime_responds.rb:107:in `respond_to'
/Path from my machine to the app/app/controllers/recipes_controller.rb:43:in `update'
나는 이것을 디버깅하는 방법에 대해 전혀 모른다. 그리고이 오류를 어떻게 올릴 수 있는지 이해할 수 없다.
모든 도움은 진정으로 감사합니다.
감사
해결책
비 HTML 클라이언트에 응답하지 않는 경우 respons_to를 사용할 필요가 없습니다.
방법을 다음과 같이 변경하십시오.
if @recipe.update_attributes(params[:recipe])
redirect_to :action => "edit"
end
작동하면 오류는 앱의 MIME 유형 구성 어딘가에있는 것처럼 보입니다.
다른 팁
이 암호 오류는 수율을 사용하지 않을 때 나타납니다. 체재 물체. 사실, 당신은 update_attributes 호출이 실패 할 때 실제로 무언가를해야합니다. 예를 들어 편집하다 주형:
def update
@recipe = Recipe.find(params[:id])
respond_to do |format|
if @recipe.update_attributes(params[:recipe])
format.html { redirect_to [:edit, @recipe] }
else
format.html { render :template => 'edit' }
end
end
end
제휴하지 않습니다 StackOverflow