flypig 2008-9-3 11:44
请教《应用Rails...》中store_helper的问题
在《应用Rails...》中文第二版127页(9.4节)中,隐藏空购物车的所有代码改完之后,浏览器中点击Add to Cart会出错,如下图:
[attach]868[/attach]
点击后提示:
[attach]869[/attach]
与下载的该书源码对比后发现,本节中修改了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]而下载的源码为:[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[/code]使用第二段代码的话就不会出错。。
不知道为什么,有人遇到过这个问题嘛?哪位达人帮我解释一下呀,好迷茫。