[英]ruby on rails: (eval):1: syntax error, unexpected $undefined
我收到以下语法错误:
(eval):1: syntax error, unexpected $undefined
$#<MenuBuilder:0x007fccee84e7f8> = #<MENUBUILDER:0X007FCCEE84E7F8>
^
这是代码执行:
#main-menu
= menu do |m|
= m.submenu "Products" do
= m.item "Products", Product
module BuildersHelper
def menu(options = {}, &block)
MenuBuilder.new(self).root(options, &block)
end
end
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行。
问题似乎出在您使用capture
助手方法时 。
该方法接受一个视图代码块,并将其分配给可以在视图中其他地方使用的变量。
这是更多信息: http : //api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#method-i-capture
您确定要传递代码到执行捕获的代码中吗?
您可能会考虑这样的事情:
content_tag :li do
if block_given?
content_tag(:h6, title.t) +
content_tag(:ul, capture(self, &block), :class => "ui-corner-all")
else
content_tag(:h6, title.t) # whatever is appropriate if there's no block passed
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.