Forum: Ruby on Rails deprecation warning in Rails 3 about Base.named_scope

Posted by daze (Guest)
on 2010-09-01 18:04
(Received via mailing list)
I recently upgraded to Rails 3, and this error has come up
ubiquitously:

DEPRECATION WARNING: Base.named_scope has been deprecated, please use
Base.scope instead.

Any ideas on how to get rid of it?  Or should I just wait for
something?
There's actually no place in my application where the code
"Base.named_scope" exists, so I assume the problem is inherent in gems
that haven't gotten up to speed with Rails 3 yet.

Someone on stackoverflow also posted this issue:
http://stackoverflow.com/questions/3333612/how-to-avoid-deprecation-warning-with-named-scope-rails-2-x-scope-rails-3-c

I'd appreciate any help.  Thanks in advance =].
Posted by Marnen Laibow-Koser (marnen)
on 2010-09-01 18:11
daze wrote:
> I recently upgraded to Rails 3, and this error has come up
> ubiquitously:
> 
> DEPRECATION WARNING: Base.named_scope has been deprecated, please use
> Base.scope instead.
> 
> Any ideas on how to get rid of it?  Or should I just wait for
> something?
> There's actually no place in my application where the code
> "Base.named_scope" exists, 

That literal string doesn't have to be present; it's just the qualified 
name of the method being called.  Are you calling named_scope anywhere?

> so I assume the problem is inherent in gems
> that haven't gotten up to speed with Rails 3 yet.
> 
> Someone on stackoverflow also posted this issue:
> http://stackoverflow.com/questions/3333612/how-to-avoid-deprecation-warning-with-named-scope-rails-2-x-scope-rails-3-c
> 
> I'd appreciate any help.  Thanks in advance =].

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
Posted by Adam (Guest)
on 2010-09-01 18:44
(Received via mailing list)
On Wed, Sep 1, 2010 at 10:22 AM, daze <dmonopoly10@gmail.com> wrote:

> I recently upgraded to Rails 3, and this error has come up
> ubiquitously:
>
> DEPRECATION WARNING: Base.named_scope has been deprecated, please use
> Base.scope instead.
>
> Any ideas on how to get rid of it?  Or should I just wait for
> something?
>

ActiveRecord's named_scope was changed to scope in Rails 3, and uses the 
new
ActiveRecord query interface.
See also:
http://edgerails.info/articles/what-s-new-in-edge-rails/2010/02/23/the-skinny-on-scopes-formerly-named-scope/


> There's actually no place in my application where the code
> "Base.named_scope" exists, so I assume the problem is inherent in gems
> that haven't gotten up to speed with Rails 3 yet.
>

If you aren't using any named_scopes, then it sounds like you might want 
to
isolate the problem to a specific gem or plugin and log a bug with the
author. Try creating a new Rails 3 project and adding your gems one by 
one.


>
> Someone on stackoverflow also posted this issue:
>
> http://stackoverflow.com/questions/3333612/how-to-avoid-deprecation-warning-with-named-scope-rails-2-x-scope-rails-3-c
>
> I'd appreciate any help.  Thanks in advance =].
>

Adam
Posted by daze (Guest)
on 2010-09-01 22:37
(Received via mailing list)
okay, thanks...I think I might try that. (I did not have any
occurrences of named_scope anywhere in my code, just for
clarification)

I noticed though that the problem seems to stem from the
acts_as_authentic line in my User model.  might that mean anything?
what exactly is that line anyway....
Posted by Hassan Schroeder (Guest)
on 2010-09-01 23:41
(Received via mailing list)
On Wed, Sep 1, 2010 at 1:37 PM, daze <dmonopoly10@gmail.com> wrote:

> I noticed though that the problem seems to stem from the
> acts_as_authentic line in my User model.  might that mean anything?
> what exactly is that line anyway....

Presumably you put it there? :-)

Anyway, from a project of my own:

$ find  -type f -name '*.rb' -exec grep -H 'acts_as_authentic'  {} \;
    app/models/user.rb:  acts_as_authentic do |c|
    vendor/gems/authlogic-2.1.6/lib/authlogic/acts_as_authentic/base.rb:
   # Provides the base functionality for acts_as_authentic

$ find vendor/gems/authlogic-2.1.6 -type f -name '*.rb' -exec grep
'named_scope' {} \;
            named_scope :logged_in, lambda { {:conditions =>
["last_request_at > ?", logged_in_timeout.seconds.ago]} }
            named_scope :logged_out, lambda { {:conditions =>
["last_request_at is NULL or last_request_at <= ?",
logged_in_timeout.seconds.ago]} }
...
$

FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.