Search code examples
ruby-on-railsip-addressrake-taskgeocode

Getting location(city, state) from ip_address for bulk data with rake task


I have an x users with their last_sign_in_ip, can i get their location details using their ip_address with rake task? I am using rails and geocoder gem.


Solution

  • Since you have the geocoder gem, use this:

    Geocoder.search(user.last_sign_in_ip)
    

    It will return a json with the address elements.