I try to concat nested div tag in rails.
foo = ''
foo.concat content_tag :div do
label_tag 'bar'
end
=> "<div></div>"
But it always returns div tag without inner tag.
Why did happened?
Due to ruby scoping complete block passed to concat not content_tag
separately. You can concat returned string using +
operator. Try below code.
foo = ''
foo += content_tag :div do
label_tag 'bar'
end
=> "<div><label for="bar">Bar</label></div>"
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.