2015-02-10 2 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

Paste вам контроллеры код –

+0

Вы только POST против статей/{ArticleID}/комментарии, так же, как линия 4 ваших маршрутов говорит. Какая черта «/: create» там? – railsdog

ответ

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

Смежные вопросы