字体:  

请教《应用Rails...》中store_helper的问题

flypig 发表于: 2008-9-03 11:44 来源: Ruby Community

在《应用Rails...》中文第二版127页(9.4节)中,隐藏空购物车的所有代码改完之后,浏览器中点击Add to Cart会出错,如下图:


error1.jpg


点击后提示:


error2.jpg



与下载的该书源码对比后发现,本节中修改了depot/app/helpers/store_help.rb如下:

CODE:

module StoreHelper
  
  def hidden_div_if(condition, attributes = {})
    if condition
      attributes["style"] = "display: none"
    end
    attrs = tag_options(attributes.stringify_keys)
    "<div #{attrs}>"
  end
end
而下载的源码为:

CODE:

module StoreHelper
  
  def hidden_div_if(condition, attributes = {}, &block)
    if condition
      attributes["style"] = "display: none"
    end
    content_tag("div", attributes, &block) # The different line
  end
end
使用第二段代码的话就不会出错。。
不知道为什么,有人遇到过这个问题嘛?哪位达人帮我解释一下呀,好迷茫。