我有一个NoMethodError undefined method `where' for <Subscription:0x000001083aee00>
。它指向我的用户型号subscription.where(cancelled: nil).exists?
。NoMethodError undefined method'where'
在视图中,我试图设置if语句,以便我可以向订阅表中的取消状态不为零的用户显示选择的内容。
用户模式:
has_one :subscription
def paid?
subscription.where(cancelled: nil).exists?
end
的has_one
关系是从一开始就对应用程序的其他部分。当我加入belongs_to
关系,我得到的错误undefined method `where' for nil:NilClass
您使用的是哪种版本的导轨? – dax
@dax我有Rails 4 – xps15z