編集:
私の以前の解決策は機能しませんでした:)
それを指摘してくれたEmFiに感謝します。
今回、私はそれを(さえ)テストしました、そしてそれは(さえ)働きました!\ o /
このブログ投稿に基づいて、これをここに投稿しています。
はるかに良い説明のために完全な投稿を読んでください:)
app / helpers / application_helper.rb
def block_to_partial(partial_name, options = {}, &block)
options.merge!(:body => capture(&block))
concat(render(:partial => partial_name, :locals => options), block.binding)
end
app / views / xxx / new.html.haml
%h2 Test!
- block_to_partial("block_large", :class_name=>"nested_content") do
This is some nested content
OOps..
app / views / xxx / _block_large.html.haml
#block_large
%img(src="block_large_carat.gif" class="block_large_carat")
%div(class=class_name)
= body
レンダリング:
<div id='block_large'>
<img class='block_large_carat' src='block_large_carat.gif' />
<div class='nested_content'>
This is some nested content
</div>
</div>
OOps..
お役に立てば幸いです。