我正在关注入门指南: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:
答案 0 :(得分:2)
确保您拥有7.2 Associating Models
class Comment < ActiveRecord::Base
belongs_to :post
end
应该在post
实例上生成comment
方法。