If you pass an array as a value, ActiveRecord is smart enough to compare its inclusion in the array. For instance,
Book.where(:author_id => [1, 7, 42])
creates an SQL query with a WHERE similar to:
WHERE "author_id" IN (1, 7, 42)
You can use this in scope just as you would set normal conditions:
class Book < ....
Then you can pass a single ID or an array of identifiers to by_author and it will work:
Book.by_author([1,7,42])
David source share