V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iloveyou
V2EX  ›  Ruby on Rails

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

  •  
  •   iloveyou · 2012-01-17 23:14:32 +08:00 · 4532 次点击
    这是一个创建于 4727 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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>
    5 条回复    1970-01-01 08:00:00 +08:00
    iloveyou
        1
    iloveyou  
    OP
       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
        2
    iloveyou  
    OP
       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
        3
    pepsin  
       2012-01-17 23:22:20 +08:00
    21行那个comment没有对应的实例变量或者是方法吧?
    goophy
        4
    goophy  
       2012-01-17 23:27:46 +08:00 via iPhone
    18: <% @post.comments.each do |commnet| %>
    拼写错误 commnet -> comment
    iloveyou
        5
    iloveyou  
    OP
       2012-01-18 11:36:03 +08:00
    @goophy 我晕,我思索几天的问题啊,2b青年啊我
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2584 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 15:39 · PVG 23:39 · LAX 07:39 · JFK 10:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.