-
-
Save tomciopp/adef30cb458c1177df2b to your computer and use it in GitHub Desktop.
This file contains 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
This is the code that is in my load model: | |
acts_as_mappable | |
before_validation :geocode_shipping, :geocode_delivery | |
private | |
def geocode_shipping | |
geo = Geokit::Geocoders::MultiGeocoder.geocode(shipping_address) | |
errors.add(:shipping_address, "Could not geocode shipping address") unless geo.success | |
self.shipping_latitude, self.shipping_longitude = geo.lat, geo.lng if geo.success | |
end | |
def geocode_delivery | |
geo2 = Geokit::Geocoders::MultiGeocoder.geocode(delivery_address) | |
errors.add(:delivery_address, "Could not geocode delivery address") unless geo2.success | |
self.delivery_latitude, self.delivery_longitude = geo2.lat, geo2.lng if geo2.success | |
end | |
The code for the controller is the same as the geocoder gem. | |
This is the error that I get when I use the geokit gem: | |
NoMethodError in LoadsController#create | |
undefined method `error' for nil:NilClass | |
Rails.root: /Users/thomascioppettini/rails_projects/want-freight | |
Application Trace | Framework Trace | Full Trace | |
app/models/load.rb:53:in `geocode_shipping' | |
app/controllers/loads_controller.rb:47:in `block in create' | |
app/controllers/loads_controller.rb:46:in `create' | |
Request | |
Parameters: | |
{"utf8"=>"✓", | |
"authenticity_token"=>"6plIaIeiOOCXu5RG/ckOaCQHaAwt/AubtAXmVYuExAM=", | |
"load"=>{"shipping_address"=>"1834 Wake Forest Rd, | |
Winston Salem, | |
NC", | |
"shipping_date"=>"2011-10-02", | |
"shipping_time(1i)"=>"", | |
"shipping_time(2i)"=>"", | |
"shipping_time(3i)"=>"", | |
"shipping_time(4i)"=>"05", | |
"shipping_time(5i)"=>"30", | |
"delivery_address"=>"1 Infinite Loop, | |
Cupertino, | |
CA", | |
"delivery_date"=>"2011-10-03", | |
"delivery_time(1i)"=>"", | |
"delivery_time(2i)"=>"", | |
"delivery_time(3i)"=>"", | |
"delivery_time(4i)"=>"21", | |
"delivery_time(5i)"=>"00", | |
"truck_type"=>"1", | |
"notes"=>""}, | |
"commit"=>"Create Load"} | |
Show session dump | |
Show env dump | |
Response | |
Headers: | |
None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment