【发布时间】:2017-09-26 06:00:58
【问题描述】:
我有一个字符串数组,用作模型中where 调用的参数。
如何在模型where 调用中附加每个字符串并返回活动记录关系以进行额外的limit 调用
我尝试了以下方法,但它只将第一项添加到 where 子句中
array = ['active = true', 'expired = false', 'created_at > 2017-04-18 10:36:28']
array.reduce { | item | Post.where(item) }
返回
Posts.where('active = true')
而我却在乞求
Posts.where('active = true').where('expired = false').where('created_at > 2017-04-18 10:36:28')
谢谢。
【问题讨论】:
标签: ruby-on-rails arrays ruby loops activerecord