2017-02-08 9 views
0

Post 개체의 중첩 된 리소스 인 Comment을 삭제하려고합니다.rails 5 중첩 된 리소스 삭제

ActionController :: CommentsController #에서 ParameterMissing PARAM 파괴가 없거나 값이 비어 :

def comments_params 
    ActionController::Parameters.permit_all_parameters = true 
    params.required(:comment).permit(:author,:body) 
end 

:

추출 소스를 언급

나는이 메시지가 나타납니다 코드는 다음과 같습니다.

및 뷰는 (부분 _comment.html.erbpostshow.html.erb 호출)

<%= link_to 'Destroy Comment', [comment.post,comment], 
    method: :delete, 
    data: { confirm: 'Are you sure?' } %> 

요청 파라미터는 :

{ "_method"=> "authenticity_token"를 "삭제"=> "XXXXXXXXXXXXXXXXXXXXXXXXXXX" "post_id를"=> "테스트 2", "ID"= ""3 "}

comments_param 메서드에서 다른 매개 변수를 추가하려고했지만 문제를 해결하는 데 도움이되지 않습니다.

감사합니다.

+0

이 게시물은 유효한 post_id처럼 보이십니까? "post_id"=> "test-2" – saadlulu

+0

post_id가 friendly_id 보석 때문에 post_id가 "2"인 경우에도 동일한 결과가 발생합니다. –

답변

0

다음에 특정 설명을 삭제 한 후.

before_filter :find_comment, :only => [:destroy] 

    def destroy 
     @comment.destroy 
    end 

    def find_comment 
     @comment = Comment.get(params[:id]) 
    end 

    private 

    def comments_params 
     params.required(:comment).permit(:author,:body) 
    end 
+0

귀하의 솔루션과 동일한 결과 ... –