【发布时间】:2018-02-28 13:31:04
【问题描述】:
有没有可能使用类似的东西
scope :state, ->(state) {
merge(where("start_time <= ? and end_time >= ?", Time.now.utc.beginning_of_day, Time.now.utc.beginning_of_day)) if state.include?("open")
merge(where("end_time < ?", Time.now.utc.beginning_of_day)) if state.include?("closed")
merge(where("start_time > ?", Time.now.utc.beginning_of_day)) if state.include?("upcoming")
}
如果我使用这个范围,只有最后一个是有效的。
例如:
- state(["upcoming"]) -> 工作
- state(["open"]) -> 未使用的地方
- state(["deleted"], ["upcoming"]) -> 仅在使用即将到来的条件时使用
【问题讨论】:
标签: ruby-on-rails ruby scope