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?
The ternary operator is a common Ruby idiom that makes a quick if/else statement easy and keeps it all on one line. The ternary operator uses a combination of the ? and : .
The ternary operator is used to return a value based on the result of a binary condition. It takes in a binary condition as input, which makes it similar to an 'if-else' control flow block. It also, however, returns a value, behaving similar to a function.
The conditional ternary operator assigns a value to a variable based on some condition. This operator is used in place of the if-else statement. The operator first evaluates for a true or false value and then, depending upon the result of the evaluation, executes one of the two given statements.
i know that the '?' in ruby is something that checks the yes/no fulfillment.
<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' %>">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With