2016-07-15 11 views
0

: 작업을 비교Michael Hartl의 튜토리얼 그림 13.54에있는 마이크로 포스트에 대한 삭제 http 요청에 경로 일치가 없습니다? 섹션의 <a href="https://www.railstutorial.org/book/user_microposts#code-micropost_user_mismatch_test" rel="nofollow">following excerpt</a>에서

ActionController::UrlGenerationError: No route matches 
{:action=>"/microposts/583546149", :controller=>"microposts"} 

: 부분을 내가 본 한 조각에

test "should redirect destroy for wrong micropost" do 
    log_in_as(users(:michael)) 
    micropost = microposts(:ants) 
    assert_no_difference 'Micropost.count' do 
    delete micropost_path(micropost) 
    end 
    assert_redirected_to root_url 
end 

다음 줄

delete micropost_path(micropost) 

는 나에게 다음과 같은 오류를주고 있었다 전형적인 삭제 HTTP 요청의 온라인 뭔가가 본질적으로 잘못되었다는 내게 단서. 나는 호기심 튜토리얼에서 마이클 하틀 일반적으로 자원을 삭제하는 다음 구문을 사용했다고도 언급했다 :

delete :destroy, id: micropost 

그냥 명확하게하기 위해, 후자는 예상대로 작동하는 것 같다. 내 질문은 두 가지입니다.

둘 다 유효합니까? 차이점이 뭐야?

답변

0

이 테스트는 방법이 마이크로 포스트 (: 오렌지)이기 때문에 마이크로 포스트 (: 개미)를 만들 수 없는지 확인하는 것입니다. 그것이 오류를 내고 리다이렉트 된 이유입니다. 그래서 시험은 통과되었다.

테스트 구문이 다를 수 있습니다.