erb中的Ruby三元运算符? [英] Ruby ternary operator in erb?
本文介绍了erb中的Ruby三元运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使此代码看起来更好:
How can I make this code look better:
<%=raw manuscript.uploaded_to_s3? ? "<span style=\"color:green;\">" : "<span style=\"color:red;\">" %>
也就是说,HTML是否可以超出ERB块的范围,从而使其更易于阅读?
That is, can the HTML go outside of the ERB block making this easier to read?
推荐答案
<span style="color:<%= manuscript.uploaded_to_s3? ? 'green' : 'red' %>">
我主张使用CSS类而不是样式属性8P:
I would advocate a CSS class rather than style attribute 8P:
<span class="<%= manuscript.uploaded_to_s3? ? 'green' : 'red' %>">
这篇关于erb中的Ruby三元运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文