0

I'm doing an app where I need to request the user's latitude and longitude by his IP.

I've tried any other solution from stack overflow but they all seem outdated and doesn't work very well, like this one Geocoder, how to test locally when ip is 127.0.0.1?.

What is the way I can call request.location when in localhost?

1 Answers1

1
class ApplicationController < ActionController::Base
    before_action :ip_print

    def ip_print
        if Rails.env.production?
            puts "Ip Address: #{request.remote_ip}"
        else
            ip = Net::HTTP.get(URI.parse('http://checkip.amazonaws.com/')).squish
            puts "Ip Address: #{ip}"
        end
    end
end
7urkm3n
  • 6,054
  • 4
  • 29
  • 46
  • Thanks. How should I call it in the controller? If I call "request.location" I get: "#"::1", "bogon"=>true}, @cache_hit=nil>" – Aldo Witzke Jun 12 '19 at 17:56