检查集合中是否存在某些参数

Check for presence of some parameter in a set

我的搜索引擎从参数中检索了一些搜索过滤器,但如果没有 "filter" 参数,我需要做其他事情。

我之前在做

params.slice(*filter_params).any?

但我现在得到了

DEPRECATION WARNING: Method any? is deprecated and will be removed in Rails 5.1, as ActionController::Parameters no longer inherits from hash. Using this deprecated behavior exposes potential security problems. If you continue to use this method you may be creating a security vulnerability in your app that can be exploited. Instead, consider using one of these documented methods which are not deprecated: http://api.rubyonrails.org/v5.0.0.rc1/classes/ActionController/Parameters.html

我不确定我可以做什么来替换这里的 .any? 调用?

您可以将其替换为 Object#present?:

params.slice(*filter_params).present?

您可以在 params 上调用 .to_h 以获取您习惯的哈希方法。

你可以使用!.blank?或者 !.empty?