I’m trying to localize my users throught their IP address. As the docs say, a class method called geocode_ip_address has been mixed into the ActionController::Base. But there must be something I’m missing. Do I have to define a filter like this before_filter :geocode_ip_address to use it? (I want to know the location for every request done).
The documentation also talks about “A first-time lookup will result in the GeoLoc class being stored in the session as :geo_location” but I certainly don’t have that key inside the session hash.
What am I doing wrong?
Thanks.
You don’t need to prepend before_filter to geocode_ip_address, but rather just put that in your controller:
Note that if the geocoding fails geo will be nil. If you’re running in development you’ll be trying to geocode 127.0.0.1, so you’ll want to set your remote_ip in the request object. I did so by adding this to the bottom of config/environments/development.rb: