apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

bug if address is nil (exception undefined .empty? for Nil) #368

Closed jpwynn closed 11 years ago

jpwynn commented 11 years ago

It looks to me like there is a subtle bug where the geocode assumes the address field is non-nil. Specifically, it looks to me that when it is going to geocode (gmap is nil for example) the gem does a check for address.empty? which throws an exception if address is nil.

If so, maybe it should be checking address.to_s.empty?

Rails 3.2.13, ruby 1.9.3p429

Here's a quick way to see it:

f = Foo.last

f.update_attributes :address => nil

# true

f.update_attributes :address => nil, :gmaps => false

# NoMethodError: undefined method `empty?' for nil:NilClass

f.update_attributes :address => '', :gmaps => false

# no error

FWIW my model has acts_as_gmappable :validation => false