0
我正在模板中定義一個塊,並將其傳遞給部分並將其呈現爲字符串,但調用部分內部的塊似乎將渲染到模板上下文中?Ruby部分塊渲染不按順序
LIB/test.rb
class Test
def render(&block)
view = ApplicationController.new()
view.class_eval do
include ApplicationHelper
end
view.render_to_string(:partial => 'cool_partial', :locals => {
:block => block
})
end
end
控制器/ action.haml
= @test_obj.render do |variable|
%td='hello-world'
應用程序/視圖/ _cool_partial.haml
%table
%tr
(0..5).each do |i|
block.call
輸出
<td>hello-world</td>
<td>hello-world</td>
<td>hello-world</td>
<td>hello-world</td>
<td>hello-world</td>
<table>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</table>