Say I have a user model, and there is a ton of user information, such as email, date of birth, location, phone number, etc.
What is the easiest way to hide attributes that are empty?
I'm doing something like
<% if blog.title.empty? -%>
<p>Body: <%=h blog.body %></p>
<p>Comments: <%=h blog.comments %></p>
<% elsif blog.body.empty? %>
<p>Title: <%=h blog.title %></p>
<p>Comments: <%=h blog.comments %></p>
<% else -%>
<p>Title: <%=h blog.title %></p>
<p>Body: <%=h blog.body %></p>
<% end -%>
Clearly, this is one ugly child. Besides using partial images for rendering, is there a trick to show only empty fields?
I am trying to write a helpher method to make the view cleaner, but it is even more ugly.
Any help is appreciated.
source
share