To clean and factor ugly views, I'd like to do the following:
1) In the view:
= document_left_container do
= document_information
2) In my helper:
def document_left_container(&block)
render partial: "/document_left_container", locals: { custom_block: block }
end
def document_information
render partial: "document_information"
end
3) Partials:
For document_left_container:
.foo
= custom_block.call
For document_information:
.bar
4) The expected result:
<div class='foo'>
<div class='bar'>
</div>
</div>
5) The actual result:
<div class='foo'>
</div>
<div class='bar'>
</div>
Does anyone know how I could do to get my stuff working?
Thanks in advance,
Ben
My current solution is:
Helper:
Partial:
Rest remains unchanged, I really wanted to keep the same structure.
Still curious to understand why my original code failed.
I think your original code failed because you were essentially calling render and then calling render again. So you pushed something onto the stack and then pushed something else onto it. If you did this I think it would work. (Although I haven't tested it.)
Here's how I'd keep it DRY:
This will produce