[英]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.