Rails 4 - undefined method `call' when doing a simple query

匆匆过客 提交于 2019-11-28 21:23:50

Rails 4+ requires named scopes to be a lambda and not just a simple Relation.

Change the old version

scope :active, where(is_active: true)

to the lambda version

scope :active, lambda { where(is_active: true) }

or even shorter to

scope :active, -> { where(is_active: true) }

For more information about named scopes and how to pass parameters, I suggest reading about Scopes in the Rails Guide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!