app/jobs/auth_trail/geocode_job.rb in authtrail-0.1.3 vs app/jobs/auth_trail/geocode_job.rb in authtrail-0.2.0

- old
+ new

@@ -1,21 +1,27 @@ module AuthTrail - class GeocodeJob < Rails::VERSION::MAJOR >= 5 ? ApplicationJob : ActiveJob::Base + class GeocodeJob < ActiveJob::Base def perform(login_activity) result = begin Geocoder.search(login_activity.ip).first rescue => e Rails.logger.info "Geocode failed: #{e.message}" nil end if result - login_activity.update!( - city: result.try(:city).presence, - region: result.try(:state).presence, - country: result.try(:country).presence - ) + attributes = { + city: result.try(:city), + region: result.try(:state), + country: result.try(:country), + latitude: result.try(:latitude), + longitude: result.try(:longitude) + } + attributes.each do |k, v| + login_activity.try("#{k}=", v.presence) + end + login_activity.save! end end end end