Combining html and ruby -
i have html code in rails application looks this:
<td><%= myobj.find_by_id(@my_obj.some_id).name %></td>
and shows fine. however, field some_id
not present in database, i'd display na
rather myobj
's name in cases.
so here's mean in pseudocode:
<td><%= if @my_obj.some_id nil "na" else myobj.find_by_id(@my_obj.some_id).name %></td>
how can this?
you can use following snippet:
<td><%= @my_obj.some_id.present? ? myobj.find(@my_obj.some_id).name : 'na' %></td>
however, you're exposing pretty big issues if you're finding records in view code this. controller should handle kind of logic.
Comments
Post a Comment