Jessicascn
Jessicascn

Reputation: 161

Geocoder request location returns nil in production

I've been trying to get the user current location with geocoder gem but it crashes in production and returns "nil" everytime.

I've tried with a different IP, another computer, same thing... I've tried to use .safe_location but it's nil too.

Here is my code, just in case:

  @location = request.safe_location

  unless @location.nil?
     @places = Place.near([@location.latitude, @location.longitude])
  end

Just for information, I've tried we request.location.city too. Still "no method for nil class".

I've used geocoder on 10 different apps I've coded and never had this problem. It was with Heroku everytime though, first time with AWS.

I am also using geocoder to get Place.near(params[:address]) and that works fine, so I can confirm the gem implementation is fine.

Where could that come from?

Thanks a lot!

Upvotes: 1

Views: 537

Answers (1)

Luca C.
Luca C.

Reputation: 3

These methods will usually return nil in test and development environments because things like localhost and 0.0.0.0 are not geocodable IP addresses.

Read full docs here

Upvotes: 0

Related Questions