1

我正在关注 Rails 入门教程:http ://guides.rubyonrails.org/getting_started.html 代码与此处相同,我不明白。我在第十行的“comments.post”做错了什么?

NoMethodError in Posts#show

Showing /Users/franklinexpress/rails_projects/wal/app/views/comments/_comment.html.erb              

其中第 10 行提出:

undefined method `post' for #<Comment:0x007ff05072c110>

提取的源代码(第 10 行附近):

7:      <b>Comment:</b>
8:      <%= comment.comment %>
9:      </p>
10:         <%= link_to 'Destroy Comment', [comment.post, comment],
11:                         :confirm => 'Are you sure?',
12:                         :method => :delete %>
13:             
4

1 回答 1

2

确保你有这个7.2 Associating Models

class Comment < ActiveRecord::Base
  belongs_to :post
end

这应该在实例上生成post方法。comment

于 2012-02-06T05:56:35.347 回答