简体   繁体   English

如何从Rails控制台反向地理编码记录?

[英]How can I reverse geocode records from the Rails console?

Why wouldn't 为什么不

Location.where(address: nil).each do |location|
    location.reverse_geocode
    location.save!
end

work, while 工作,而

class Location < ActiveRecord::Base
    reverse_geocoded_by :latitude, :longitude
    after_validation :reverse_geocode
end

reverse geocodes any new locations? 反向地理编码是否有新位置? The console doesn't error, it just returns the activerecord relation with the address values still nil. 控制台不会出错,它只返回地址值仍然为零的activerecord关系。

try with this 试试这个

location.address = location.reverse_geocode
location.save!

So my original solution worked, I just had to restart my machine. 因此,我原来的解决方案起作用了,我只需要重启机器即可。 Strangely, restarting the console, server, and editor did nothing, so I suspect some dark magic is going on with RVM. 奇怪的是,重新启动控制台,服务器和编辑器并没有执行任何操作,因此我怀疑RVM正在发生一些不可思议的事情。

Thanks for the help, everyone. 谢谢大家的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM