我偶然发现了HAML如何处理Rails中render
方法的不一致。
ERB中的示例1 :
# template.html.erb
This is the index template.
<%= render :layout => 'form4', :partial => 'stuff2' %>
# _layout.html.erb
<%= form_tag do %>
<div class="something">
<%= yield %>
</div>
<% end %>
# _partial.html.erb
<b>meh</b>
<%= text_field_tag 'name' %>
HAML
中的示例1# template.html.haml
This is the index template.
=render :layout => 'form2', :partial => 'stuff1'
# _layout.html.haml
=form_tag do
.something
=yield
# _partial.html.haml
%b meh
=text_field_tag 'name'
正如预期的那样,两者都会产生相同的渲染(缩写如下):
This is the index template.
<form>
<div class="something">
<b>meh</b>
<input id="name" name="name" type="text" />
</div>
</form>
现在,这里是,奇怪之处在于。当我调整render
语句以使用块语法时如下:
在 ERB :
中# template.html.erb
This is the index template.
<%= render :layout => 'form3' do %>
<b>meh</b>
<%= text_field_tag 'name' %>
<% end %>
# _layout.html.erb
<%= form_tag do %>
<div class="something">
<%= yield %>
</div>
<% end %>
在 HAML :
中# template.html.haml
This is the index template.
=render :layout => 'form1' do
%b meh
=text_field_tag 'name'
# _layout.html.haml
=form_tag do
.something
=yield
我在ERB版本中获得了相同的上述渲染,但是HAML代码输出:
This is the index template.
<b>meh</b>
<input id="name" name="name" type="text" />
<form>
<div class='something'></div>
</form>
就好像HAML以某种方式不尊重传递给它的块。根据HAML的文档,他们支持基于缩进自动关闭的块,所以我不怀疑这是一个问题。另外,在他们的文档中,我看到了他们自己的render
方法的定义。是否可能没有正确实现与rails(erb's?)render
方法相同的接口?
在这方面,如果这在方法界面中确实存在不一致,那么在HAML上打开问题是否合理呢?
刚刚添加了一个展示https://github.com/iamvery/haml-weirdness
行为的示例应用值得注意的是,当我将rails应用程序升级到3.0.9并将haml升级到3.1.2时,我注意到了这一变化。将haml保留为3.0.24会导致rails 3.0.9中出现Cannot modify SafeBuffer in place
错误...
答案 0 :(得分:2)
是的,我遇到了同样的问题。它也在https://github.com/nex3/haml/issues/412 described进行了描述 在nex3的github帐户上有一个issue_412分支,但它不完整。 你可以尝试修复haml,我决定回到rails 3.0.7。