我的助手中有这个:
def favorites_count(node)
content_tag :span, class: "card-favorite-count" do
content_tag :i, class: "icon-heart"
node.cached_votes_total
end
end
在视图中这样调用:
<%= favorites_count(node) %>
这就导致了:
<span class="card-favorite-count"></span>
我如何让它渲染整个东西?
Edit 1
根据下面@tolgap的建议,我尝试了这个:
def favorites_count(node)
content_tag :span, class: "card-favorite-count" do
content_tag(:i, "" ,class: "icon-heart") + node.cached_votes_total
end
end
但这并没有输出数值node.cached_votes_total
。但它会以正确的语义顺序输出其他所有内容。这只是最后一部分还没有发挥作用。
中的最后一个表达式do
块content_tag
就是内容是什么。所以将其更改为:
def favorites_count(node)
content_tag :span, class: "card-favorite-count" do
node.cached_votes_total + content_tag(:i, class: "icon-heart")
end
end
所以你将这两者连接在一起。当然,你需要做nil
检查node.cached_total_votes
now.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)