初学ror,使用官方那个blog例子,卡在这里了,求指点。我用rails 3.1.3

2012-01-17 23:14:32 +08:00
 iloveyou
Showing /Users/Sites/blog/app/views/posts/show.html.erb where line #21 raised:

undefined local variable or method `comment' for #<#<Class:0x007fc394660120>:0x007fc394663aa0>
Extracted source (around line #21):

18: <% @post.comments.each do |commnet| %>
19: <p>
20: <b>Commenter:</b>
21: <%= comment.commenter%>
22: </p>
23: <p>
24: <b>Comment:</b>
4506 次点击
所在节点    Ruby on Rails
5 条回复
iloveyou
2012-01-17 23:15:35 +08:00
posts model:

class Post < ActiveRecord::Base
validates :name, :presence => true
validates :title, :presence => true, :length => { :minimum => 5 }

has_many :comments
end


comments model:

class Comment < ActiveRecord::Base
belongs_to :post
end
iloveyou
2012-01-17 23:15:48 +08:00
posts model:

class Post < ActiveRecord::Base
validates :name, :presence => true
validates :title, :presence => true, :length => { :minimum => 5 }

has_many :comments
end


comments model:

class Comment < ActiveRecord::Base
belongs_to :post
end
pepsin
2012-01-17 23:22:20 +08:00
21行那个comment没有对应的实例变量或者是方法吧?
goophy
2012-01-17 23:27:46 +08:00
18: <% @post.comments.each do |commnet| %>
拼写错误 commnet -> comment
iloveyou
2012-01-18 11:36:03 +08:00
@goophy 我晕,我思索几天的问题啊,2b青年啊我

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/25774

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX