弃用警告:不推荐使用Model.scoped

时间:2017-11-30 13:08:20

标签: ruby-on-rails ruby-on-rails-4 deprecation-warning

我有以下警告:

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

简单的改变产品.scoped到products.all我收到

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

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

1 个答案:

答案 0 :(得分:0)

看起来products已经是一个数组了,所以你应该可以在没有products的情况下使用.all

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