ruby on rails - Case statement in a view -


i have auditlog things id, action, type, description...

what i'd in view like:

case description   when "created"     <li>created styling</li>   when "deleted"     <li>deleted styling</li>   else     <li>error</li> end 

trying learn how in view , correct syntax, resources found on google don't specify.

if styling contains lots of tags , html elements, suggest putting them partials:

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

if description created, render file _created.html.erb in same folder current view

if deleted, render _deleted.html.erb automatically.

if description else, has no _something.html.erb file, nothing displayed (without rescue nil, error occurs)

======

if want render partial in different folder,

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

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -