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?

Answers


<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' %>">

Need Your Help

REST URL design for greater than, less than operations

api url rest

I am having a bit of difficulty designing a url for a rest service that can handle requests for customers based on pagination as one type of operation or requesting greater than or less than operat...

Visual Studio - Automatically refresh class view when changing class

.net visual-studio visual-studio-2008 eclipse ide

I come from a Java background and have spent many years using Eclipse. One feature that I miss when using Visual Studio (2008) is that the class view does not automatically refresh when I change cl...