I have a view helper method that takes a block. Render that block is no problem, but when I try to add content after the block is rendered, it does not work.
def validation_div(&block)
content_tag :div do
yield
content_tag :div do
'This content is never rendered!'
end
end
end
The above code just yields the block and skips the other content. I have also tried with: content_for
, capture
, concat
and with_output_buffer
without any success. As you notice, I don't really understand how these methods work... But my question is: how to render something after the given block is rendered. Thanks!
If you look at a content_tag definition, you see it only outputs one tag, one class, and one content. You're trying to get it out out multiple contents so you'll need to join them.
def validation_div(&block)
content = capture(&block)
content_tag :div do
content + content_tag(:div , "This content is never rendered!")
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.