Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 轨道4.1。Heroku ActiveRecord::StatementInvalid(PG::UndefinedFunction:错误:运算符不存在:数字-字符变化_Ruby On Rails_Ruby_Postgresql_Activerecord_Heroku - Fatal编程技术网

Ruby on rails 轨道4.1。Heroku ActiveRecord::StatementInvalid(PG::UndefinedFunction:错误:运算符不存在:数字-字符变化

Ruby on rails 轨道4.1。Heroku ActiveRecord::StatementInvalid(PG::UndefinedFunction:错误:运算符不存在:数字-字符变化,ruby-on-rails,ruby,postgresql,activerecord,heroku,Ruby On Rails,Ruby,Postgresql,Activerecord,Heroku,这是我的控制器,我在这里点击查询: def search_by_location @stores = Store.includes(:images).near([params[:latitude], params[:longitude]], 10) end 在本地机器上一切都很好。在PG上,Heroku出现了一个错误 以下是日志: 2016-06-23T08:04:56.392549+00:00 heroku[router]: at=info method=POST path="/api/

这是我的控制器,我在这里点击查询:

def search_by_location
  @stores = Store.includes(:images).near([params[:latitude], params[:longitude]], 10)
end
在本地机器上一切都很好。在PG上,Heroku出现了一个错误

以下是日志:

2016-06-23T08:04:56.392549+00:00 heroku[router]: at=info method=POST path="/api/customer/search_by_location?type=daeal&page=1" host=loyelte.herokuapp.com request_id=0364888a-3866-4acd-bea0-17a4bf4eaeee fwd="122.162.251.21" dyno=web.1 connect=0ms service=14ms status=500 bytes=1669
2016-06-23T08:04:56.362768+00:00 app[web.1]: Started POST "/api/customer/search_by_location?type=daeal&page=1" for 122.162.251.21 at 2016-06-23 08:04:56 +0000
2016-06-23T08:04:56.365114+00:00 app[web.1]: Processing by Customer::CustomersController#search_by_location as */*
2016-06-23T08:04:56.365163+00:00 app[web.1]:   Parameters: {"latitude"=>"28", "longitude"=>"77", "type"=>"daeal", "page"=>"1", "customer"=>{}}
2016-06-23T08:04:56.366751+00:00 app[web.1]:   Authentication Load (0.8ms)  SELECT  "authentications".* FROM "authentications" WHERE "authentications"."auth_token" = $1 AND "authentications"."subject_type" = $2 LIMIT 1  [["auth_token", "41360d38bef547ab8e9ae2ce47459c53"], ["subject_type", "Customer"]]
2016-06-23T08:04:56.368775+00:00 app[web.1]:   Customer Load (0.9ms)  SELECT  "customers".* FROM "customers" WHERE "customers"."id" = $1 LIMIT 1  [["id", 3]]
2016-06-23T08:04:56.371919+00:00 app[web.1]:   Store Load (1.4ms)  SELECT stores.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((28.0 - stores.latitude) * PI() / 180 / 2), 2) + COS(28.0 * PI() / 180) * COS(stores.latitude * PI() / 180) * POWER(SIN((77.0 - stores.longitude) * PI() / 180 / 2), 2))) AS distance, MOD(CAST((ATAN2( ((stores.longitude - 77.0) / 57.2957795), ((stores.latitude - 28.0) / 57.2957795)) * 57.2957795) + 360 AS decimal), 360) AS bearing FROM "stores" WHERE (stores.latitude BETWEEN 27.85526821688915 AND 28.14473178311085 AND stores.longitude BETWEEN 76.83608111706583 AND 77.16391888293417 AND (3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((28.0 - stores.latitude) * PI() / 180 / 2), 2) + COS(28.0 * PI() / 180) * COS(stores.latitude * PI() / 180) * POWER(SIN((77.0 - stores.longitude) * PI() / 180 / 2), 2)))) BETWEEN 0.0 AND 10)  ORDER BY distance ASC
2016-06-23T08:04:56.372212+00:00 app[web.1]: Completed 500 Internal Server Error in 7ms (ActiveRecord: 3.1ms)
2016-06-23T08:04:56.373468+00:00 app[web.1]: 
2016-06-23T08:04:56.373476+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR:  operator does not exist: numeric - character varying
2016-06-23T08:04:56.373477+00:00 app[web.1]: LINE 1: ...*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((28.0 - stores.l...
2016-06-23T08:04:56.373477+00:00 app[web.1]:                                                              ^
2016-06-23T08:04:56.373478+00:00 app[web.1]: HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
2016-06-23T08:04:56.373479+00:00 app[web.1]: : SELECT stores.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((28.0 - stores.latitude) * PI() / 180 / 2), 2) + COS(28.0 * PI() / 180) * COS(stores.latitude * PI() / 180) * POWER(SIN((77.0 - stores.longitude) * PI() / 180 / 2), 2))) AS distance, MOD(CAST((ATAN2( ((stores.longitude - 77.0) / 57.2957795), ((stores.latitude - 28.0) / 57.2957795)) * 57.2957795) + 360 AS decimal), 360) AS bearing FROM "stores" WHERE (stores.latitude BETWEEN 27.85526821688915 AND 28.14473178311085 AND stores.longitude BETWEEN 76.83608111706583 AND 77.16391888293417 AND (3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((28.0 - stores.latitude) * PI() / 180 / 2), 2) + COS(28.0 * PI() / 180) * COS(stores.latitude * PI() / 180) * POWER(SIN((77.0 - stores.longitude) * PI() / 180 / 2), 2)))) BETWEEN 0.0 AND 10)  ORDER BY distance ASC):

根据我们对OP的评论,他正在使用
geocoder
gem。必须将
latitude
longitude
字段的表字段设置为
float

在安装geocoder gem后,迁移是否在Heroku deploy上成功运行?确保迁移设置了
latitude
longitudee> 您的
表中的字段将
存储到
float
。感谢您的精彩回复。当我将
纬度
经度
字段数据类型更改为
float
后,它对我起到了作用。让我将其添加为未来谷歌和extra+25:)的答案