# Problem with built-in named scope all

**URL:** <https://www.ruby-forum.com/t/problem-with-built-in-named-scope-all/144330>\
**Category:** Rails\
**Created:** [July 28, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/problem-with-built-in-named-scope-all/144330 "2008-07-28T18:45:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cah4i](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cah4i](https://www.ruby-forum.com/u/cah4i)\
**Post date:** [July 28, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/problem-with-built-in-named-scope-all/144330/1 "2008-07-28T18:45:40Z")

</div>

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

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.count  
> > NoMethodError: 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

---

<div class="post-metadata">

**Author:** ![cah4i](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bc8723/32.png) [@cah4i](https://www.ruby-forum.com/u/cah4i)\
**Post date:** [July 28, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/problem-with-built-in-named-scope-all/144330/2 "2008-07-28T21:27:55Z")

</div>

On Jul 28, 11:19 am, cah4i [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

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](http://purpleworkshops.com)
