Skip to content

Instantly share code, notes, and snippets.

@paulmederos
Created June 27, 2012 02:07
Show Gist options
  • Save paulmederos/3000862 to your computer and use it in GitHub Desktop.
Save paulmederos/3000862 to your computer and use it in GitHub Desktop.
Organization Gist for MapBox integration
class Organization < ActiveRecord::Base
# ... more irrelevant code ...
geocoded_by :full_address
after_validation :geocode, :if => :address_1_changed? || :city_changed? || :state_changed?
def full_address
"#{address_1} #{city}, #{state}"
end
def geo
if self.latitude.present? && self.longitude.present? && self.address_1.present?
return "{ \"type\": \"Feature\",
\"geometry\": {
\"type\": \"Point\", \"coordinates\": [#{self.longitude}, #{self.latitude}]
}, \"properties\": {\"name\" : \"#{self.name}\", \"url\" : \"http://foster.ly/organizations/#{self.id}\",
\"description\" : \"#{self.summary}\", \"type\" : \"#{Organization::CATEGORIES[self.organization_category]}\",
\"webpage\" : \"#{self.webpage}\" }
},"
else
return ""
end
end
# ... more irrelevant code ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment