Reputation: 3814
I have the following code in my Calls controller:
@calls = Call.where(:destination => ("1234"),
:destination => ("5678"),
:destination => ("91011"))
Although the above code works, it's only listing records with a destination of 91011. I would somehow like to show all records of which the destination field matches any of the numbers.
I'm unsure as to whether or not I should be adding a .where statement for each filter or not.
Any help would be appreciated!
This is very similar to another question I asked a while ago. However, that was to further filter a find condition rather than widen the scope.
Upvotes: 0
Views: 577
Reputation: 230336
Try this:
@calls = Call.where(:destination => ["1234", "5678", "91011"])
Also, if you're on ruby 1.9, you can use the new hash syntax:
@calls = Call.where(destination: ["1234", "5678", "91011"])
For a limit, there's a method
@calls = Call.where(destination: ["1234", "5678", "91011"]).limit(10)
I strongly suggest you read about ActiveRecord Query Interface, it's awesome!
Upvotes: 5