3

我有这样的麻烦:我想使用 ajax 请求来获取用户位置,所以我在我的控制器中创建了动作并在 json 中呈现 Geocoder 函数的结果。这是代码:

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

在本地它工作得很好,在heroku上它也可以工作,但是当我将此代码添加到另一个项目时 - 它向我显示了这个错误

   NameError in ConnectionsController#find_location

   uninitialized constant ConnectionsController::Geocoder

这很奇怪,因为这是在控制台中工作的:

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

我试图包含 Geocoder::Model,但它不起作用。

有人能帮我吗 ?

4

3 回答 3

4

基于这个问题,您必须重新启动整个生产机器,而不仅仅是您的 apache 或 nginx。

我实际上不得不打开一个问题,因为它对我不起作用。 https://github.com/alexreisner/geocoder/issues/501

于 2013-08-17T18:41:50.677 回答
1

确保你geocoder gem的没有分组在里面:development,或者:test里面Gemfile

它应该在组之外,以便我可以在所有环境中访问

前任:

#Gemfile

group :development, :test do
  #your gems
end 

gem 'geocoder'
于 2013-02-09T15:06:01.350 回答
0

您是否有机会将 Docker 用于您的后端代码?

如果你这样做了,那么在你安装任何 gem 之后,你需要停止 Rails 容器,构建(或者如果你使用 dockerhub 从 dockerhub 下拉)新的镜像,然后再次启动你的容器。

一切都很好

于 2018-07-18T14:15:01.863 回答