I have a message inbox. I would like to display each message in different background based on its read status (read/not read).
My @messages variable contain multiple messages, each of which has an attribute called read_at.
My question is: how do I apply class to these items dynamically based on their read status?
You can do this with rails like this
Then you can set the style for read/unread messages accordingly in your css file.
In case you’re unfamiliar, this line
<%= m.read_at.nil? ? "unread" : "read" %>is a ternary statement. This explains it pretty succinctly http://en.wikipedia.org/wiki/Ternary_operation#Ruby