"comments"}" />

Rails - 没有路线匹配 {:action=>"new", :controller=>"comments"}

发布于 2024-12-08 15:07:25 字数 1744 浏览 0 评论 0 原文

尝试了所有方法,似乎无法找到问题所在。

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 路由 的相关部分

$ 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"}

我可能会缺少什么这里?

Tried everything, can't seem to locate the issue.

Error on localhost:3000

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

Error in server

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 has my resources nested

  resources :tasks do
    resources :comments    
  end

and the relevant section of my $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"}

What could I be missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幼儿园老大 2024-12-15 15:07:25

您没有向其传递 task_id

new_task_comment_path(@task.id)

You aren't passing it a task_id:

new_task_comment_path(@task.id)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文