Is there possible to use something like
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")
}
If I use this scope, only the last one is functional.
for example:
- state(["upcoming"]) -> work
- state(["open"]) -> where is not used
- state(["deleted"], ["upcoming"]) -> only where with upcoming conditions is used
You should be able to use
Notice that you should do
instead of
Also you can use Array.wrap to simplify using the scope:
With state being wrapped you can use the scope in both following ways:
hope this solve your problem.