Denys Medynskyi
Denys Medynskyi

Reputation: 2353

Can't use Geocoder class in my controller

I have such trouble: I want to use ajax request to get user location, so I created action in my controller and rendering the result of Geocoder function in json. Here is code:

  def find_location
   location = Geocoder.coordinates(params[:location])
   render :json => (location)
  end

Locally it works great, on heroku it works too, but when I added this code to another project - it shows me this error

   NameError in ConnectionsController#find_location

   uninitialized constant ConnectionsController::Geocoder

It is strange, because this is working in console:

      Geocoder.coordinates "Ukraine"
       => [48.379433, 31.16558] 

I tried to include Geocoder::Model, but it doesn't work.

Can someone help me ?

Upvotes: 3

Views: 2949

Answers (3)

Andre Song
Andre Song

Reputation: 363

Do you use Docker for your backend code by any chance?

If you do so, then after you installed any gem, you need to stop the Rails container, build (or pull down from dockerhub if you use dockerhub) the new image, and start your containers again.

All is well 👍

Upvotes: 0

rderoldan1
rderoldan1

Reputation: 4078

Based on this issue you have to restart the whole production machine, not only your apache or nginx.

I actually had to open an issue because it doesn't work for me. https://github.com/alexreisner/geocoder/issues/501

Upvotes: 4

sameera207
sameera207

Reputation: 16619

make sure your geocoder gem is not grouped inside :development, or :test inside the Gemfile

it should be outside the groups so that I could accessed in all the environments

Ex:

#Gemfile

group :development, :test do
  #your gems
end 

gem 'geocoder'

Upvotes: 1

Related Questions