弃用警告:Model.scoped 已弃用

DEPRECATION WARNING: Model.scoped is deprecated

我有以下警告:

 DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead.

这里是带范围

的行
products = ((params.nil? || params[:search].blank?) ? products.scoped : products.filter_with_criterias(params[:search].split(" "), options))
products = ((params.nil? || params[:state].blank?) ? products.scoped : products.where(state: params[:state]))

简单地将products.scoped更改为products.all后,我收到了

Failure/Error: products = ((params.nil? || params[:state].blank?) ? 
products.all : products.where(state: params[:state]))

NoMethodError:
  undefined method `all' for []:Array

看起来 products 已经是一个数组,所以你应该可以只使用 products 而不用 .all:

products = ((params.nil? || params[:state].blank?) ? products : products.where(state: params[:state]))