Closed
Description
BEFORE POSTING AN ISSUE, PLEASE MAKE SURE THE PROBLEM IS NOT ADDRESSED IN THE README!
Expected behavior
object.geocode => nil
Actual behavior
object.geocode =>
NoMethodError: undefined method `[]' for nil:NilClass
from /usr/local/lib/ruby/gems/2.4.0/gems/geocoder-1.5.1/lib/geocoder/results/base.rb:47:in `latitude'
from /usr/local/lib/ruby/gems/2.4.0/gems/geocoder-1.5.1/lib/geocoder/stores/active_record.rb:300:in `block in geocode'
from /usr/local/lib/ruby/gems/2.4.0/gems/geocoder-1.5.1/lib/geocoder/stores/base.rb:110:in `do_lookup'
from /usr/local/lib/ruby/gems/2.4.0/gems/geocoder-1.5.1/lib/geocoder/stores/active_record.rb:298:in `geocode'
Noticed that when using Geocoder.search
with the invalid zip get back a result.
results = Geocoder.search("10300")
results.first
=> #<Geocoder::Result::SmartyStreets:0x000055729111ebe0 @data={"input_index"=>0, "status"=>"invalid_zipcode", "reason"=>"Invalid ZIP Code."}, @cache_hit=true>
Because the result is not an empty array I thought it might be causing some issues.
Steps to reproduce
# config/initializers/geocoder.rb
Geocoder.configure(
lookup: :smarty_streets,
api_key: ['auth_id', 'auth_token'],
)
rails g model address zip
rails db:migrate
class Address < ApplicationRecord
geocoded_by :zip
end
address = Address.create(zip: "10300")
address.geocode
Environment info
- Geocoder version: 1.5.1
- Rails version: 5.0.0
- Database (if applicable):
- Lookup (if applicable): Smartystreets