2015-02-10 33 views
0

所以我正在开发一个简单的Ruby on Rails应用程序。它实际上基于官方教程,你可以在http://guides.rubyonrails.org/getting_started.html找到。我将测试扩展到教程的范围之外。使用的测试框架是SimpleCov。使用POST与RoR时找不到路由

3) Error: 
CommentsControllerTest#test_Rcomment_-_Create_(S): 
ActionController::UrlGenerationError: No route matches {:action=>"/articles/201799169/:create", :comment=>{:alias=>"Somebody", :text=>"Some plain text"}, :controller=>"comments"} 
    test/controllers/comments_controller_test.rb:13:in `block (2 levels) in <class:CommentsControllerTest>' 
    test/controllers/comments_controller_test.rb:12:in `block in <class:CommentsControllerTest>' 



    Prefix Verb URI Pattern          Controller#Action 
     welcome_index GET /welcome/index(.:format)       welcome#index 
       root GET /            welcome#index 
    article_comments GET /articles/:article_id/comments(.:format)   comments#index 
        POST /articles/:article_id/comments(.:format)   comments#create 
new_article_comment GET /articles/:article_id/comments/new(.:format)  comments#new 
edit_article_comment GET /articles/:article_id/comments/:id/edit(.:format) comments#edit 
    article_comment GET /articles/:article_id/comments/:id(.:format)  comments#show 
        PATCH /articles/:article_id/comments/:id(.:format)  comments#update 
        PUT /articles/:article_id/comments/:id(.:format)  comments#update 
        DELETE /articles/:article_id/comments/:id(.:format)  comments#destroy 
      articles GET /articles(.:format)        articles#index 
        POST /articles(.:format)        articles#create 
     new_article GET /articles/new(.:format)       articles#new 
     edit_article GET /articles/:id/edit(.:format)      articles#edit 
      article GET /articles/:id(.:format)       articles#show 
        PATCH /articles/:id(.:format)       articles#update 
        PUT /articles/:id(.:format)       articles#update 
        DELETE /articles/:id(.:format)       articles#destroy 




test "Rcomment - Create (S)" do 
    article = articles(:valid) 
    article.save 
    assert_difference('Comment.count') do 
     post '/articles/' + article.id.to_s + '/:create', comment: { alias: 'Somebody', text: 'Some plain text' } 
    end 
    assert_response :redirect 
    assert_redirected_to article_path(assigns(:article)) 
    end 
+0

粘贴你的控制器代码 – 2015-02-10 00:52:03

+0

你刚才发布针对文章/ {}条款ArticleID /评论,就像你的路线线4说要。到底是什么“/:创造”? – railsdog 2015-02-10 01:06:30

回答

0

您尝试发布的方法不存在。您需要发布到:create

post :create, article_id: article.id, 
    comment: { alias: 'Somebody', text: 'Some plain text' } 
+0

感谢您的回复,但不幸的是这个建议不起作用。我还是会得到“无路线匹配{:action =>”/ articles/201799169/comments“,:comment => {:alias =>”Somebody“,:text =>”Some plain text“},:controller =>”注释”}”。 – Sp333th 2015-02-10 01:49:36