title: What's an elegant way to conditionally add a class to an HTML element in a view?
body: <p>I occasionally have to add a class to an html element based on a condition. The problem is I can't figure out a clean way of doing it. Here's an example of the stuff I've tried:</p>
  
  <pre><code>&lt;div &lt;%= if @status = 'success'; "class='ok'"; end %&gt;&gt;
     some message here
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>OR</strong></p>
  
  <pre><code>&lt;% if @status == 'success' %&gt;
     &lt;div class='success'&gt;
  &lt;% else %&gt;
     &lt;div&gt;
  &lt;% end %&gt;
     some message here
  &lt;/div&gt;
  </code></pre>
  
  <p>I don't like the first approach because it's crowded looking and hard to read. I don't like the second approach because the nesting is screwed up. It'd be nice to put it in the model, (something like <code>@status.css_class</code>), but that doesn't belong there. What do most people do?</p>