How can determine if an item has a value or not?

When i execute the followin code i get the following message:
"comparison of Time with String failed"

<% @auftrag.attributes.each do |key, item| %>

  <%if item > "" %>
    <b>Key: <%= key %>:</b>
    Item: <%= item %>
  <%end%>

<%end%>

One of the fields in my database is a datefield and seems not to work
with > ""
How can determine if an item is filled or not?

tia

When i execute the followin code i get the following message:
"comparison of Time with String failed"

<% @auftrag.attributes.each do |key, item| %>

<%if item > "" %>
   <b>Key: <%= key %>:</b>
   Item: <%= item %>
<%end%>

<%end%>

One of the fields in my database is a datefield and seems not to work
with > ""
How can determine if an item is filled or not?

Use either item.nil? or item.blank?

Hi Einar,

Einar Kretzler wrote:

How can determine if an item is filled or not?

<% unless item.nil? %>

HTH,
Bill

Bill Walton wrote:

Hi Einar,

Einar Kretzler wrote:

How can determine if an item is filled or not?

<% unless item.nil? %>

HTH,
Bill

Thanks, but there are still the empty key -- items shown

<% @auftrag.attributes.each do |key, item| %>
<% unless item.nil? %>
    <b>Key: <%= key %></b>
    <%= item %>
<%end%>
<%end%>

produces something like:
Key: sonst_verm Key: gemeinschaft Key: whg_verm Key: updated_at Tue Jul
22 16:23:44 +0200 2008 Key: hs_verm Key: format werwer Key: etw_vk Key:
anzeigentext lkjl Key: fioport ljkkjhj Key: art jklhjlk Key: immo_sonst
Key: gesuch_immo Key: dateien Key: zeitung_sonst Key: id 4 Key: zeitung
newspapername Key: immo_vk Key: ang_gewerbe Key: sonder_hoehe Key:
sonder_breite Key: ersch_datum 2008-07-21 Key: spalten 8 Key: created_at
Mon Jul 21 21:04:40 +0200 2008

i want to get rid of the empty key --values pairs where there are no
entries in the database

Try

<% unless item.empty? %>

Regards
Kieran

Einar Kretzler wrote:

Bill Walton wrote:
> Hi Einar,
>
> Einar Kretzler wrote:
>
>> How can determine if an item is filled or not?
>
> <% unless item.nil? %>
>
> HTH,
> Bill

Thanks, but there are still the empty key -- items shown

<% @auftrag.attributes.each do |key, item| %>
<% unless item.nil? %>
    <b>Key: <%= key %></b>
    <%= item %>
<%end%>
<%end%>

produces something like:
Key: sonst_verm Key: gemeinschaft Key: whg_verm Key: updated_at Tue Jul
22 16:23:44 +0200 2008 Key: hs_verm Key: format werwer Key: etw_vk Key:
anzeigentext lkjl Key: fioport ljkkjhj Key: art jklhjlk Key: immo_sonst
Key: gesuch_immo Key: dateien Key: zeitung_sonst Key: id 4 Key: zeitung
newspapername Key: immo_vk Key: ang_gewerbe Key: sonder_hoehe Key:
sonder_breite Key: ersch_datum 2008-07-21 Key: spalten 8 Key: created_at
Mon Jul 21 21:04:40 +0200 2008

i want to get rid of the empty key --values pairs
where there are no entries in the database

Sorry about that. Changing item.nil? to item.blank? should take care of the
other items. blank? returns true for both nil and an empty string.

Best regards,
Bill

thanks item.blank has made the trick :slight_smile: