Skip to content

Instantly share code, notes, and snippets.

@codespectator
Created November 16, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codespectator/4090817 to your computer and use it in GitHub Desktop.
Save codespectator/4090817 to your computer and use it in GitHub Desktop.
class Job < ActiveRecord::Base
include NearbyMethods
end
module NearbyMethods
include ActiveSupport::Concern
def nearby(asset, radius=10)
asset.singularize.constantize.find_near(self.latlng, radius) # forget nearby and do a radius search
end
end
So you can do:
Job.first.nearby(:jobs)
or
@company.nearby(:companies)
or
@job.nearby(:companies)
@mcoms
Copy link

mcoms commented Nov 17, 2012

Why not Company.near(Job.first)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment