title: Conditionally add a css class in views, not using erb?
body: <p>Is it possible, and if so, is it suggested?  </p>
  
  <p>I want to add a class to an element if a condition is true. The only way I can figure out how to do this is using erb in the view itself using something like:  </p>
  
  <pre><code>&lt;div &lt;%= if @status == 'success'; "class='do-something'"; end %&gt;&gt;
     message
  &lt;/div&gt;
  </code></pre>
  
  <p>or using <code>div_for</code> but it's messy and I'd much rather set the class of an html element using a helper or methods in the model/controller itself. something like:  </p>
  
  <p>If action succeeds, find the html element somehow (by data attribute, by class, etc) and add a class to it.</p>