I have a Rails 3 scope that excludes an array of ids.
What is the best way to write the scope so that it does nothing when the array is empty and is still chainable? I c
If the ids array is empty then don't return anything.
ids
scope :excluding_ids, lambda { |ids| where(['id NOT IN (?)', ids]) if ids.any? }
The query will run without any additional constraints on the query if there are no ids.