Ruby ternary operator in erb?

2019-02-16 12:21发布

How can I make this code look better:

<%=raw manuscript.uploaded_to_s3? ? "<span style=\"color:green;\">" : "<span style=\"color:red;\">" %>

That is, can the HTML go outside of the ERB block making this easier to read?

1条回答
Evening l夕情丶
2楼-- · 2019-02-16 13:04
<span style="color:<%= manuscript.uploaded_to_s3? ? 'green' : 'red' %>">

I would advocate a CSS class rather than style attribute 8P:

<span class="<%= manuscript.uploaded_to_s3? ? 'green' : 'red' %>">
查看更多
登录 后发表回答