# Helper + conditional loop

**URL:** <https://www.ruby-forum.com/t/helper-conditional-loop/106945>\
**Category:** Rails\
**Created:** [June 15, 2007, 3:49pm UTC](https://www.ruby-forum.com/t/helper-conditional-loop/106945 "2007-06-15T15:49:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![apsingh1981](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@apsingh1981](https://www.ruby-forum.com/u/apsingh1981)\
**Post date:** [June 15, 2007, 3:49pm UTC](https://www.ruby-forum.com/t/helper-conditional-loop/106945/1 "2007-06-15T15:49:51Z")

</div>

hi everyone ,

I am new to RoR thing , i am building an application in that i am  
filling the text field with items present in my database …thus using  
code like this :

```
 <% if @lost_pro_d.disease != "" %>
Disease: <%= @lost_pro_d.disease %><br />
 <% end %>
 <% if @lost_pro_d.noticable_mark != ""%>
Noticeable Marks: <%= @lost_pro_d.noticable_mark%><br />
 <% end %>
 <% if @lost_pro_d.habits != ""%>
Habits: <%= @lost_pro_d.habits%>
 <% end %>

```

what am i trying is to use helper thing for this …can anyone guide  
me how to do this thing ???

Anant

---

<div class="post-metadata">

**Author:** ![apsingh1981](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@apsingh1981](https://www.ruby-forum.com/u/apsingh1981)\
**Post date:** [June 15, 2007, 5:48pm UTC](https://www.ruby-forum.com/t/helper-conditional-loop/106945/2 "2007-06-15T17:48:17Z")

</div>

Anant S. wrote:

> hi everyone ,
> 
> I am new to RoR thing , i am building an application in that i am  
> filling the text field with items present in my database …thus using  
> code like this :
> 
> ```
> <% if @lost_pro_d.disease != "" %>
> Disease: <%= @lost_pro_d.disease %><br />
> <% end %>
> <% if @lost_pro_d.noticable_mark != ""%>
> Noticeable Marks: <%= @lost_pro_d.noticable_mark%><br />
> <% end %>
> <% if @lost_pro_d.habits != ""%>
> Habits: <%= @lost_pro_d.habits%>
> <% end %>
> 
> ```
> 
> what am i trying is to use helper thing for this …can anyone guide  
> me how to do this thing ???
> 
> Anant

In your helper:

def display\_if\_present(desc, item)  
return “” if item.blank?  
return “#{desc}: #{item}  
”  
end

In the view:

\<%= display\_if\_present(‘Disease’, @lost\_pro\_d.disease %\>

steve
