Case statement in a view

I have an AuditLog with things like id, action, type, description...

What I'd like to do in the view is something like:

case description
  when "created"
    <li>created styling</li>
  when "deleted"
    <li>deleted styling</li>

Trying to learn how to do this in a view and the correct syntax, which the resources I found on Google don't specify.


If your styling contains lots of tags and HTML elements, I would suggest putting them into partials:

<%= render :partial => @audit_log.description rescue nil %>

If you description is created, then it would render the file _created.html.erb in the same folder as the current view

If it is deleted, render _deleted.html.erb automatically.

If description is something else, which has no _something.html.erb file, then nothing would be displayed (without rescue nil, error will occurs)


If you want to render the partial in some different folder,

<%= render :partial => "some/where/#{@audit_log.description}" %>

This should work:

  case @audit_log.description
  when "created" then "created styling"
  when "deleted" then "deleted styling"
  else "error"

actually it would be better and easier to use Jquery's addclass function

Need Your Help

Turn all textboxes into WYSIWYG HTML Editors using PageMod

javascript firefox-addon textarea firefox-addon-sdk nicedit

I am trying to create an addon that turns all textareas on certain pages into WYSIWYG HTML editors. I tried using PageMod by calling the NicEdit library and then running a content script with the c...

installing python package - no logging configuration


I have just installed a python package called "Bacon", but whenever I import it, it comes up with a few errors.