ruby-on-rails-3 - Rails - 没有路由匹配 { :action= >"new", :controller= >"comments"}

标签 ruby-on-rails-3 routes new-operator

什么都试过了,还是找不到问题所在。
localhost:3000 上的错误

No route matches {:action=>"new", :controller=>"comments"}

服务器出错
Rendered tasks/show.html.erb within layouts/application (134.7ms)
Completed 500 Internal Server Error in 187ms

ActionView::Template::Error (No route matches {:action=>"new", :controller=>"comments"}):
    66: 
    67: <br />
    68: 
    69: <%= link_to 'New Comment', new_task_comment_path %>
    70: 
    71: 
    72: 
  app/views/tasks/show.html.erb:69:in `_app_views_tasks_show_html_erb___1205853643464254853_2489437560'
  app/controllers/tasks_controller.rb:18:in `show'
Routes.rb嵌套了我的资源
  resources :tasks do
    resources :comments    
  end

以及我的 $rake routes 的相关部分
$ rake routes
    task_comments GET    /tasks/:task_id/comments(.:format)          {:action=>"index", :controller=>"comments"}
                  POST   /tasks/:task_id/comments(.:format)          {:action=>"create", :controller=>"comments"}
 new_task_comment GET    /tasks/:task_id/comments/new(.:format)      {:action=>"new", :controller=>"comments"}
edit_task_comment GET    /tasks/:task_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
     task_comment GET    /tasks/:task_id/comments/:id(.:format)      {:action=>"show", :controller=>"comments"}
                  PUT    /tasks/:task_id/comments/:id(.:format)      {:action=>"update", :controller=>"comments"}
                  DELETE /tasks/:task_id/comments/:id(.:format)      {:action=>"destroy", :controller=>"comments"}

我会在这里错过什么?

最佳答案

你没有通过 task_id :

new_task_comment_path(@task.id)

关于ruby-on-rails-3 - Rails - 没有路由匹配 { :action= >"new", :controller= >"comments"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7701358/

相关文章:

ruby-on-rails - Rails 3 - CanCan 错误? NameError(未初始化的常量 Ability::Invitation):

ruby - Rails 中输入的隐式清理 : Why do these examples from the API work the way they do?

javascript - 验证 angularjs 中的路由

c++ - 未定义的新运算符如何导致 C++ 中的未定义行为?

c++ - 为指针删除或分配零

ruby-on-rails - rails 3.2 : Select option not remembered

ruby - 我如何通过将current_user传递给Scope来确保它,从而仅给我关联关系数据

php Laravel ~ 属性 [controller] 不存在

asp.net - 如何在 MVC3 中使用 https 生成绝对 URL?

检测到 C++ 堆损坏 - CRT