Created
June 27, 2012 02:07
-
-
Save paulmederos/3000862 to your computer and use it in GitHub Desktop.
Organization Gist for MapBox integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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