Forum: Ruby on Rails helper + conditional loop

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
690d4709a310243d970970036f811f75?d=identicon&s=25 Anant Singh (apsingh1981)
on 2007-06-15 15:49
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
19990e3fa0fc68c874f42f13d1500011?d=identicon&s=25 Steve Rawlinson (trip)
on 2007-06-15 17:48
Anant Singh 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}<br/>"
end

In the view:

<%= display_if_present('Disease', @lost_pro_d.disease %>

steve
This topic is locked and can not be replied to.