I just want to create a simple "no records returned" - using this statement though @positions = pq.find if @positions.count < 1 generates "undefined method `count'' for #<Array:0x4b0adc8>" I''m not looking to apply any conditions only total records returned by the find. Anyway tell me what I''m doing wrong ? Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 14, 7:18 am, "Dark Ambient" <sambi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I just want to create a simple "no records returned" - > using this statement though > > @positions = pq.find > if @positions.count < 1 > > generates > "undefined method `count'' for #<Array:0x4b0adc8>" > > I''m not looking to apply any conditions only total records returned by the > find. > > Anyway tell me what I''m doing wrong ? > Stuart > > --http://en.wikipedia.org/wiki/Dark_ambientYou can do... "Nothing found" unless @positions.empty? or "Nothing found" if @positions.size == 0 _Kevin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can also use count_by_sql for just counting the results. Here is an example: Gift.count_by_sql("select count(distinct url) from gifts") It can be any sql statement that returns a count(). Tom On 10/14/06, _Kevin <kevin.olbrich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Oct 14, 7:18 am, "Dark Ambient" <sambi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I just want to create a simple "no records returned" - > > using this statement though > > > > @positions = pq.find > > if @positions.count < 1 > > > > generates > > "undefined method `count'' for #<Array:0x4b0adc8>" > > > > I''m not looking to apply any conditions only total records returned by the > > find. > > > > Anyway tell me what I''m doing wrong ? > > Stuart > > > > --http://en.wikipedia.org/wiki/Dark_ambient > > You can do... > > "Nothing found" unless @positions.empty? > or > "Nothing found" if @positions.size == 0 > > _Kevin > > > > >-- Tom Davies http://atomgiant.com http://gifthat.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 -~----------~----~----~----~------~----~------~--~---
On 10/14/06, _Kevin <kevin.olbrich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > > On Oct 14, 7:18 am, "Dark Ambient" <sambi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I just want to create a simple "no records returned" - > > using this statement though > > > > @positions = pq.find > > if @positions.count < 1 > > > > generates > > "undefined method `count'' for #<Array:0x4b0adc8>" > > > > I''m not looking to apply any conditions only total records returned by > the > > find. > > > > Anyway tell me what I''m doing wrong ? > > Stuart > > > > --http://en.wikipedia.org/wiki/Dark_ambient > > You can do... > > "Nothing found" unless @positions.empty? > or > "Nothing found" if @positions.size == 0 > > _KevinThanks guys (Kevin and Tom) I went with @positions.size and that works good. However , and this might be another thread all together I''m noticing a little freaky behaviour. This is an ajax form taking user conditions - what I''m finding is the first time it hits a condition that returns no records it won''t say no records found. if I go back , clear the condition and put it in again , then it will. Sound weird ? Stuart --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---