ruby-on-rails – haml_tag直接输出到Haml模板
发布时间:2020-12-16 19:21:41 所属栏目:百科 来源:网络整理
导读:我的HAML模板的帮助器出了什么问题? def display_event(event) event = MultiJson.decode(event) markup_class = get_markup_class(event) haml_tag :li,:class = markup_class do haml_tag :b,"Foo" haml_tag :i,"Bar" end end 这是错误: haml_tag output
我的HAML模板的帮助器出了什么问题?
def display_event(event) event = MultiJson.decode(event) markup_class = get_markup_class(event) haml_tag :li,:class => markup_class do haml_tag :b,"Foo" haml_tag :i,"Bar" end end 这是错误: haml_tag outputs directly to the Haml template. Disregard its return value and use the - operator,or use capture_haml to get the value as a String. 模板调用display_event,如下所示: - @events.each do |event| = display_event(event) 如果我使用常规标记,它将扩展为以下内容 %li.fooclass %b Foo %i Bar 解决方法
错误消息中的线索:
Disregard its return value and use the - operator,or use capture_haml to get the value as a String. 来自
要修复它,要么将Haml更改为: - @events.each do |event| - display_event(event) (即使用 – 运算符而不是=),或更改方法以使用 def display_event() event = MultiJson.decode(event) markup_class = get_markup_class(event) capture_haml do haml_tag :li,"Bar" end end end 这将使该方法返回一个字符串,然后您可以在Haml中显示=. 请注意,您只需要进行其中一项更改,如果您同时取消这两项更改,则不会显示任何内容. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |