Hello, I''m having a problem with the built-in all scope. For example in my Subscription model,>> Subscription.all.countNoMethodError: undefined method `count'' for #<Array:0xb5dce7f8> from (irb):46 from :0 However, my own version of all defined in the model simply as "named_scope :everything" works fine>> Subscription.everything.count=> 849 I also cannot chain scopes onto all>> Subscription.all.active.countNoMethodError: undefined method `active'' for #<Array:0xb5a80268> from (irb):50 from :0 But>> Subscription.everything.active.count=> 611 I''m relatively new to Rails so any insights people can give would be greatly appreciated. Thanks! My environment is [root@localhost trunk]# gem -v 1.1.1 [root@localhost trunk]# gem list *** LOCAL GEMS *** actionmailer (2.1.0) actionpack (2.1.0) activerecord (2.1.0) activeresource (2.1.0) activesupport (2.1.0) mysql (2.7) piston (1.4.0) rails (2.1.0) rake (0.8.1) [root@localhost trunk]# cat /etc/issue CentOS release 5.2 (Final) Kernel \r on an \m [root@localhost trunk]# uname -a Linux localhost.localdomain 2.6.18-92.1.6.el5 #1 SMP Wed Jun 25 13:49:24 EDT 2008 i686 i686 i386 GNU/Linux --~--~---------~--~----~------------~-------~--~----~ 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 Jul 28, 11:19 am, cah4i <ca...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I''m having a problem with the built-in all scope. For example in my > Subscription model, > > >> Subscription.all.count > > NoMethodError: undefined method `count'' for #<Array:0xb5dce7f8> > from (irb):46 > from :0 >Since .all internally is doing a find(:all), it''s returning an array, not an proxy like named_scope and the association methods do. So although it might look like a named scope, it actually isn''t. So instead of Subscription.all.count, you have to do Subscription.count. Instead of Subscription.all.active.count, just do Subscription.active.count. Having the "all" in there is redundant anyway, although I sympathize with the concept that it might feel more consistent that way. Jeff purpleworkshops.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---