【发布时间】:2021-06-22 12:32:30
【问题描述】:
我最近使用 ruby 2.4.5 将我的 rails 应用程序从 4.2.8 升级到 5.0.1 遇到这个错误
NoMethodError - 未定义的方法 `where_values'
查询:
PlacementActivityStep.where(query_values_hash[:query_string], query_values_hash[:values]) .where_values.select{|x| x.present?}
如何使用 where_clause 在 rails 5.0.1 中实现相同的查询,因为 where_values 已从新的 rails 版本中删除? 参考:Ruby on Rails where_values method
【问题讨论】:
-
您链接到的其他问题的答案有什么不清楚的地方吗?
-
PlacementActivityStep.where(query_values_hash[:query_string], query_values_hash[:values]) .where_clause.select{|x| x.present?} 给出 NoMethodError - 调用 #<:relation::whereclause:0x000055f5501f8f10> 的私有方法 `select'。现在该怎么办?
-
where_values_hash 能解决问题吗?
-
没有。 where_values_hash 返回哈希,而 where_values 返回 <:nodes::equality: where_clause arel ::attributes::attribute ...>
标签: ruby-on-rails ruby activerecord where-clause