Ruby on rails Geocoder Gem-获取;保留“;用于request.location.country(即使在本地!)

Ruby on rails Geocoder Gem-获取;保留“;用于request.location.country(即使在本地!),ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,rails-geocoder,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,Rails Geocoder,我需要能够看到当地的地理编码器国家和城市的输出信息,如'嗨,你在{国家检测} 为了能够在本地/开发模式下使用geocoder,我遵循了一些SO建议,并提出: 在config/environment/development.rb中 class ActionDispatch::Request def remote_ip "84.34.156.155" # fake ip for example

我需要能够看到当地的地理编码器国家和城市的输出信息,如'嗨,你在{国家检测}

为了能够在本地/开发模式下使用geocoder,我遵循了一些SO建议,并提出:

在config/environment/development.rb中

class ActionDispatch::Request
  def remote_ip
    "84.34.156.155" # fake ip for example                                                                                                                                                                                                                                                                                    
  end
end
以及在应用中的控制器

  def lookup_ip_location
    if Rails.env.development?
      Geocoder.search(request.remote_ip).first
    else
      request.location
    end
  end
在我的主页上,如果我把:

你在

它在本地显示“您处于保留状态”。它认为ip=00.00.00,而geocoder是为了返回“在这种情况下保留”而构建的

很公平,如果我输入:,它就会工作,并提供我在config/environment/development.rb:84.34.156.155中输入的IP

因此,我尝试输入“You is in”,但它不起作用,并给出错误:

undefined method `country' for 84.34.156.155":String
如何在本地显示我设置的IP位置的国家/地区

谢谢

它在生产中运行良好(它显示“你在法国!”),但不是本地

我该怎么办?我可以在本地工作和检查东西,而不必每次都部署来检查它是否工作,这是很重要的

Geocoder.search(request.remote_ip).first.country

您是否尝试过
Geocoder.search(request.remote\u ip).first.country
?正在工作!!那么,罗吉尔!当我在应用程序控制器中使用它时。我是新手!