I have this scope with the parameter city, the scope receives the parameter, joins a table call Restaurant (because I have the param there) and then it makes a where condition with IN for multiple OR.
scope :by_cities, -> (city) { joins(:restaurant).where('restaurants.city IN (?)', city) }
The thing is that I want to learn how the scope can receive an array of param in the scope, I already have tried a lot of stuff and I'm taking the guide of this guy: Rails 4 scope with argument and this: ActiveRecord where field = ? array of possible values
Logs
Parameters: {"city"=>"SanPedro"}
SELECT "vacancies".* FROM "vacancies" INNER JOIN "restaurants" ON
"restaurants"."id" = "vacancies"."restaurant_id" WHERE (restaurants.city
IN ('SanPedro'))
Route
http://localhost:3000/v1/vacancies?city=SanPedro&Monterrey
But, don't understand very well how to do it, anyone knows about this?
MyModel.by_cities([city1, city2])MyModel.by_cities('New York', 'San Fransisco')I get this error:ArgumentError: wrong number of arguments (given 2, expected 1)scope :by_cities, -> (*cities) { joins(:restaurant).where('restaurants.city IN (?)', cities) }? BTW, the docs state "Using a class method is the preferred way to accept arguments for scopes."SELECT "vacancies".* FROM "vacancies" INNER JOIN "restaurants" ON "restaurants"."id" = "vacancies"."restaurant_id" WHERE (restaurants.city IN ('Monterrey'))and I want the same but with multiple values, like this:SELECT "vacancies".* FROM "vacancies" INNER JOIN "restaurants" ON "restaurants"."id" = "vacancies"."restaurant_id" WHERE (restaurants.city IN ('Monterrey, SanPedro'))MyModel.by_cities('New York', 'San Fransisco')" - but that's not what i wrote. My example has an array, yours doesn't.