I'm trying to nest content tags into a custom helper, to create something like this:
<ul>
<li>
Microposts
<div>O</div>
</li>
</ul>
I have tried this helper:
def user_info(user)
user_microposts = content_tag(:li, ("Microposts" + " " + content_tag(:div, user.microposts.count.to_s)))
content_tag(:ul, user_microposts)
end
but it renders the div html tags in the view:
Microposts
<div>0</div>
I would be pleased to know how to manage this! Thank you
您需要将字符串标记为HTML安全,如下所示:
... "Microposts ".html_safe + content_tag(...
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.