active record 中的.where
可以将方法作为参数吗?
def not_foo?
name != "foo"
end
下面的代码不起作用,但你会明白我的意思:
array.where(|element| element.not_foo?).count
最佳答案
Can .where in active record take a method as an argument?
并且:不,它不能。也许你想这样做
array.where.not(name: 'foo').count
关于ruby - 方法作为 ActiveRecord `where` 中每个实例的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35761226/