Rails 3 / HAML: How can I output haml raw from a variable?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 15:12:32

问题


I have some variables within rails that contain some divs like so:

@layout_1 = "
.box_1 
.column_4 <br>
.gutter<br>
.column_4<br>
.gutter<br>
.column_4<br>
.gutter<br>
.column_4<br>"

This is coming from a database, and the idea is to swap layouts on request, but how can I output the variable (@layout_1) as HAML inside a HAML file ?

If I were to use normal html divs, I would use <%=raw or .html_safe


回答1:


you would do the same with HAML as well in your .html.haml view file.

= raw @layout_1

or

= @layout_1.html_safe



回答2:


Not entirely sure this works, but give it a try:

- output = Haml::Engine.new(@layout1).render
!= output


来源:https://stackoverflow.com/questions/8567841/rails-3-haml-how-can-i-output-haml-raw-from-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!