Hello people, still a newbie and just wanted to know how to actually test if resultset from find method is empty or net. Regards, Joel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Your variable will be nil. EG @accounts = Account.find(:all) if there are no records @account will be nil. On May 24, 10:42 am, joel <joel.soor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello people, > > still a newbie and just wanted to know how to actually test if > resultset from find method is empty or net. > > Regards, > > Joel--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
cherring wrote:> Your variable will be nil. > > EG > > @accounts = Account.find(:all) > > if there are no records @account will be nil.if @accounts.blank? ... else ... end -- 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 -~----------~----~----~----~------~----~------~--~---
On 24 May 2008, at 14:00, cherring wrote:> > Your variable will be nil. > > EG > > @accounts = Account.find(:all) > >Wrong. find :all returns an empty array (which you could test with foo.empty? ). find :first (or things like find_by_xxx) return nil (and find(xxx) raises ActiveRecord::RecordNotFound if there is no record with that id) Fred> > > On May 24, 10:42 am, joel <joel.soor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hello people, >> >> still a newbie and just wanted to know how to actually test if >> resultset from find method is empty or net. >> >> Regards, >> >> Joel > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ooops my mistake, live and learn, woot now I know more than before. On May 25, 8:45 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 24 May 2008, at 14:00, cherring wrote: > > > > > Your variable will be nil. > > > EG > > > @accounts = Account.find(:all) > > Wrong. find :all returns an empty array (which you could test with > foo.empty? ). find :first (or things like find_by_xxx) return nil (and > find(xxx) raises ActiveRecord::RecordNotFound if there is no record > with that id) > > Fred > > > > > On May 24, 10:42 am, joel <joel.soor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hello people, > > >> still a newbie and just wanted to know how to actually test if > >> resultset from find method is empty or net. > > >> Regards, > > >> Joel--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---