简体   繁体   中英

Ruby ternary operator in erb?

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?

<span style="color:<%= manuscript.uploaded_to_s3? ? 'green' : 'red' %>">

我会提倡CSS类而不是样式属性8P:

<span class="<%= manuscript.uploaded_to_s3? ? 'green' : 'red' %>">

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM