Ruby on rails 如何将这些方法链接在一起(地理编码器和分页)

Ruby on rails 如何将这些方法链接在一起(地理编码器和分页),ruby-on-rails,pagination,rails-geocoder,Ruby On Rails,Pagination,Rails Geocoder,我目前有一个使用geocoder gem的位置阵列: @locations=Location.near([@lat,@lon],3) 产生: => [#<Location id: 18, address: "555 N 7th Ave, Jamaica, CA 66666", phone: "(623) 555-5555", latitude: 66.666, longitude: -200.082, user_id: 1, created_at: "2015-03-11 15:

我目前有一个使用geocoder gem的位置阵列:

@locations=Location.near([@lat,@lon],3)

产生:

=> [#<Location id: 18, address: "555 N 7th Ave, Jamaica, CA  66666", phone: "(623) 555-5555", latitude: 66.666, longitude: -200.082, user_id:  1, created_at: "2015-03-11 15:06:57", updated_at: "2015-03-11 15:06:57">,

#<Location id: 46, address: "555 N 7th Ave, Jamaica, CA  66666", phone: "(623) 555-5555", latitude: 66.666, longitude: -200.082, user_id: 1, created_at: "2015-03-11 15:06:57", updated_at: "2015-03-11 15:06:57">]
在视图(haml)中:

但我得到了以下错误:

ActionView::Template::Error (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((33.457341299999996 - locations.lati' at line 1: SELECT COUNT(locations.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((33.457341299999996 - locations.latitude) * PI() / 180 / 2), 2) + COS(33.457341299999996 * PI() / 180) * COS(locations.latitude * PI() / 180) * POWER(SIN((-112.07359500000001 - locations.longitude) * PI() / 180 / 2), 2))) AS distance, MOD(CAST((ATAN2( ((locations.longitude - -112.07359500000001) / 57.2957795), ((locations.latitude - 33.457341299999996) / 57.2957795)) * 57.2957795) + 360 AS decimal), 360) AS bearing) FROM `locations`  WHERE (locations.latitude BETWEEN 33.41392176506674 AND 33.50076083493325 AND locations.longitude BETWEEN -112.12563828858949 AND -112.02155171141054 AND (3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((33.457341299999996 - locations.latitude) * PI() / 180 / 2), 2) + COS(33.457341299999996 * PI() / 180) * COS(locations.latitude * PI() / 180) * POWER(SIN((-112.07359500000001 - locations.longitude) * PI() / 180 / 2), 2)))) BETWEEN 0.0 AND 3)):

有什么想法吗?

您是否尝试过在模板中分别呈现@locations?这是我通常使用的模式:

= will_paginate
render @locations
= will_paginate

这至少可以帮助您隔离问题。

我现在也看到分页不能自然地用于普通数组(但分页集合),但仍然不理解sql错误。同样的代码对我来说非常适用。
ActionView::Template::Error (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((33.457341299999996 - locations.lati' at line 1: SELECT COUNT(locations.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((33.457341299999996 - locations.latitude) * PI() / 180 / 2), 2) + COS(33.457341299999996 * PI() / 180) * COS(locations.latitude * PI() / 180) * POWER(SIN((-112.07359500000001 - locations.longitude) * PI() / 180 / 2), 2))) AS distance, MOD(CAST((ATAN2( ((locations.longitude - -112.07359500000001) / 57.2957795), ((locations.latitude - 33.457341299999996) / 57.2957795)) * 57.2957795) + 360 AS decimal), 360) AS bearing) FROM `locations`  WHERE (locations.latitude BETWEEN 33.41392176506674 AND 33.50076083493325 AND locations.longitude BETWEEN -112.12563828858949 AND -112.02155171141054 AND (3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((33.457341299999996 - locations.latitude) * PI() / 180 / 2), 2) + COS(33.457341299999996 * PI() / 180) * COS(locations.latitude * PI() / 180) * POWER(SIN((-112.07359500000001 - locations.longitude) * PI() / 180 / 2), 2)))) BETWEEN 0.0 AND 3)):
= will_paginate
render @locations
= will_paginate