使用 Geocoder 的近方法时收到错误 PG::UndefinedColumn: ERROR: column mymodels.distance 不存在

2023-12-21

当使用此查询时(与Railscasts 第 273 集 http://railscasts.com/episodes/273-geocoder):

@locations = Location.near(params[:search], 50, :order => :distance)

或者,更简洁地说:

@mymodels = MyModel.near(address, distance, order: :distance)

我收到错误:

PG::UndefinedColumn: ERROR:  column mymodels.distance does not exist

The distance列应该添加到结果中地理编码宝石 https://github.com/alexreisner/geocoder但它似乎没有出现在结果中(所以我收到上述错误)。


当将 Postgres 与地理编码宝石 https://github.com/alexreisner/geocoder,您的查询不能使用符号化键(在这种情况下,:distance)在查询中。使用字符串'distance'在这种情况下可以避免这个问题。

@mymodels = MyModel.near(address, distance, order: 'distance')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Geocoder 的近方法时收到错误 PG::UndefinedColumn: ERROR: column mymodels.distance 不存在 的相关文章

随机推荐