2016-07-25 103 views
0

我正在使用Rails 4.2.3。我有这两款车型试图设置default_scope,但得到“支持调用#default_scope没有块被删除”错误

class Address < ActiveRecord::Base 
    … 
    has_one :user 

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

我想,当我载入我的“MyObject来”,但我得到的“default_scope”行此错误自动装入我的家长会......

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.) 

如何调整我的“default_scope”行来自动加载我的父关联?

回答

0
  • 你缺少块你行,更改它像这样:

    default_scope { includes(:address) } 
    
+0

虽然改变我行“”会导致该错误走开,我的地址实体仍然没有加载当我调用“User.find_by(id:session [:user_id])”。我已经确认实际上有一个与有问题的用户关联的地址标识。 – Dave

+0

我试过了,它为我工作。你如何验证用它加载地址......例如你是否将结果作为JSON对象发送? – Devd

相关问题