迈克尔哈特尔教程的图13.54中的微博的删除http请求没有路由匹配?

问题描述:

从部分的following excerpt迈克尔哈特尔教程的图13.54中的微博的删除http请求没有路由匹配?

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) 

是给我下面的错误:部分我看到了片段:

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

比较的动作在线的典型删除HTTP请求提示我有些事情本身就是错误的。我好奇地指出,那就是,在本教程的迈克尔·哈特尔正常使用以下语法删除资源:

delete :destroy, id: micropost 

只要是明确的,后者似乎按预期方式工作。那么我的问题是双重的:

都应该是有效的?有什么不同?

该测试是为了确保micropost(:ants)不能被创建,因为该方法是micropost(:oranges)。这就是为什么它给出了错误和重定向,这是它应该做的。所以测试通过了。

测试语法可能不同。