Search code examples
ruby-on-railsruby-on-rails-3rails-geocoder

Using the geocoder gem for rails, how do i get the visitor's city?


https://github.com/alexreisner/geocoder

I can't find documentation to show the visitor's city from ip address? I know how to with HTML5, but I would like to use the value geocoder has. Thanks


Solution

  • It took a couple of hours for me to realize that the answer is pretty simple:

    request.location.city
    

    Geocoder page has this example but I thought that I would need to declare request but no, nothing more is needed.

    If you don't have Geocoder you have to install the gem but nothing besides that.