我正在尝试设计一个辅助方法。该方法工作正常,但是html_safe(或我在此处的操作方式)无法设置样式。我尝试了其他变体,例如将html_safe放在.to_s之后,也没有用。
这是我最新的方法。
def tweeted_text(counted)
if current_user.tweets.count == 1
first = "<b>current_user.tweets.count.to_s</b>" + " Tweet"
first.html_safe
else
second = "<b>current_user.tweets.count.to_s</b>" + " Tweets"
second.html_safe
end
end
在我看来
<%= tweeted_text(@counted) %>
设置助手样式的合适方法是什么?ty
请尝试这个。
def tweeted_text
result = "<b>#{current_user.tweets.count}</b> Tweet"
result = result + "s" if current_user.tweets.count > 1
result.html_safe
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句