2015-10-29 101 views
0

我有一个奇怪的问题,我创建了一个基于this suggestion的自定义SQL函数。我有一个控制器动作create模型Route调用模型上的PG :: UndefinedFunction:ERROR:函数get_nearest_vertex_to_lon_lat(双精度,双精度)不存在

def get_route(startx, starty, endx, endy) 

    query = "SELECT seq, cost, slope::double precision, designacao::character varying(192), length::double precision," + 
    "ST_AsGeoJSON(geom) FROM pgr_dijkstra('" + 
     "SELECT gid AS id," + 
       "source::integer," + 
       "target::integer," + 
       "length AS cost " + 
       "FROM ways WHERE CAST(classif as int) <> 2'," + 
     "get_nearest_vertex_to_lon_lat(CAST(#{startx} as float) , CAST(#{starty} as float)), " + 
     "get_nearest_vertex_to_lon_lat(CAST(#{endx} as float), CAST(#{endy} as float)), false, false) a LEFT JOIN ways b ON (a.id2 = b.gid);" 

    results = ActiveRecord::Base.connection.execute(query) 
    return results 
end 

这部作品的发展,而且对生产不起作用这种方法,它提供了一个 PG::UndefinedFunction: ERROR: function get_nearest_vertex_to_lon_lat(double precision, double precision) does not exist

ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR: function get_nearest_vertex_to_lon_lat(double precision, double precision) does not exist

奇怪的是我在postgres上执行这个查询,它的工作原理。

回答

0

事实证明,尽管我的配置database.yml用于生产,但我并不知道Heroku创建了自己的生产数据库,所以显然不知道任何自定义sql函数,甚至不知道表。

以供将来参考,如果你部署到Heroku的和你使用你有一个远程数据库做this first,然后设置自己的DATABASE_URL