Reputation: 187
I have a location model and inside my locations controller I am searching for near locations using the geokit gem:
@locations = Location.near(current_user.location, 250)
How can I actually distinguish in a controller action like that whether a Location is is_remote == true
or not?
Meaning:
@locations
should actually output all the locations, which are either is_remote == true
or near(current_user.location, 250)
.
Thanks in advance for each answer! Please tell me if you need additional information.
Upvotes: 0
Views: 162
Reputation: 13531
Just add them together:
@locations = Location.near(current_user.location, 250) + Location.where(is_remote: true)
Just in case some are duplicates you can uniq
them:
@locations = (Location.near(current_user.location, 250) + Location.where(is_remote: true)).uniq
Or you can even use the Ruby set union operator instead of +
and uniq
(although some might argue it's not as readable):
@locations = Location.near(current_user.location, 250) | Location.where(is_remote: true)
Upvotes: 1