在Ruby on Rails教程的第9步中,未定义的方法`post_comment_path'

Ste*_*eve 4 methods undefined ruby-on-rails-3

[编辑:此问题的解决方案在routes.rb文件中.我在":comments"行上有"资源"而不是"资源"

我正在关注http://guides.rubyonrails.org/getting_started.html上的指南,我在第9节"删除评论".我一直在按照指南一步一步,一直在剪切/粘贴代码而不是输入代码,所以我怀疑我有一个错字 - 更像是我错过了一步.在继续学习本教程之前,我想解决这个问题,因为我是Rails的新品牌,它对我来说仍然很陌生.

知道什么是错的吗?

除了我的routes.rb:

  resources :posts do
    resource :comments
  end
Run Code Online (Sandbox Code Playgroud)

当我尝试查看带评论的帖子时,收到以下错误:

NoMethodError in Posts#show

Showing C:/Documents and Settings/stevez/Desktop/blog/app/views/comments/_comment.html.erb where line #12 raised:

undefined method `post_comment_path' for #<#<Class:0x1f13238>:0x1eecf70>
Extracted source (around line #12):

9: </p>
10: 
11: <p>
12:   <%= link_to 'Destroy Comment', [comment.post, comment],
13:                :confirm => 'Are you sure?',
14:                :method => :delete %>
15: </p>
Trace of template inclusion: app/views/posts/show.html.erb

Rails.root: C:/Documents and Settings/stevez/Desktop/blog

Application Trace | Framework Trace | Full Trace
app/views/comments/_comment.html.erb:12:in `_app_views_comments__comment_html_erb___131033543_18407100'
app/views/posts/show.html.erb:19:in `_app_views_posts_show_html_erb___843714715_14332200'
app/controllers/posts_controller.rb:18:in `show'
Request

Parameters:

{"id"=>"2"}
Show session dump

Show env dump

GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_CHARSET: "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8"
HTTP_CACHE_CONTROL: "max-age=0"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "localhost"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"
Response

Headers:

None
Run Code Online (Sandbox Code Playgroud)

Dan*_*nne 10

在您的路线中,到评论的路由也应该是复数,resources而不是resource.尝试这样做:

resources :posts do
  resources :comments
end
Run Code Online (Sandbox Code Playgroud)