Trying to set up default_scope but getting "Support for calling #default_scope without a block is removed" error

840 views Asked by At

I’m using Rails 4.2.3. I have these two models

class Address < ActiveRecord::Base
    …
    has_one :user

and

class User < ActiveRecord::Base
  belongs_to :address
  default_scope includes(:address) 

I want to auto-load my parent association when I load my “MyObject” but I’m getting this error on the “default_scope” line …

Support for calling #default_scope without a block is removed. For example instead of `default_scope where(color: 'red')`, please use `default_scope { where(color: 'red') }`. (Alternatively you can just redefine self.default_scope.)

How do I adjust my “default_scope” line to auto-load my parent association?

1

There are 1 answers

2
Devd On
  • You are missing block in your line, Change it like this:

    default_scope { includes(:address) }