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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Christopher Kintner
2008-Jul-23 20:39 UTC
Re: How can determine if an item has a value or not?
On Wed, Jul 23, 2008 at 3:30 PM, Einar Kretzler <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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?> tia > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Einar, Einar Kretzler wrote:> How can determine if an item is filled or not?<% unless item.nil? %> HTH, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Hi Einar, > > Einar Kretzler wrote: > >> How can determine if an item is filled or not? > > <% unless item.nil? %> > > HTH, > BillThanks, 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Try <% unless item.empty? %> Regards Kieran On Thu, Jul 24, 2008 at 9:13 AM, Einar Kretzler < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 databaseSorry 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---