我收到以下语法错误:
(eval):1: syntax error, unexpected $undefined
$#<MenuBuilder:0x007fccee84e7f8> = #<MENUBUILDER:0X007FCCEE84E7F8>
^
这是代码执行:
_main_menu.html.haml
#main-menu
= menu do |m|
= m.submenu "Products" do
= m.item "Products", Product
builders_helper.rb
module BuildersHelper
def menu(options = {}, &block)
MenuBuilder.new(self).root(options, &block)
end
end
menu_builder.rb
class MenuBuilder
attr_accessor :template
def initialize(template)
@template = template
end
def root(options, &block)
options[:class] = "jd_menu jd_menu_slate ui-corner-all"
content_tag :ul, capture(self, &block), options
end
def item(title, url, options = {})
content_tag :li, options do
url = ajax_route(url) unless String === url
url = dash_path + url if url.starts_with?("#")
link_to title, url
end
end
def submenu(title, options = {}, &block)
content_tag :li do
content_tag(:h6, title.t) +
content_tag(:ul, capture(self, &block), :class => "ui-corner-
all")
end
end
end
它在 root 方法中的 capture() 调用上失败:
content_tag :ul, capture(self, &block), options
self 指的是 MenuBuilder 的实例,我很肯定一个块作为另一个参数传递。如果我在 if block_given 中抛出 puts 语句?它会执行,但不会通过上面的 content_tag 行。