postgresql - How to save google.maps.Data.MultiPolygon to geometry datatype column in postgres database in rails? -
i beginner in rails framework, please pardon naive question. have google.maps.data.multipolygon
object on frontend want save in database. table searches
creates new entry everytime user searches, contains different columns out of have added column datatype :geometry
, updated when user draws polygon @ specific search. need update search entry in database, using put
call. cannot send whole google.maps.data.multipolygons
object on put call, since $.params()
unable serialise object (this problem same faced here).
var polygons = new google.maps.data.multipolygon([polygon]); var search_params = $.param({search: $.extend(this.state.search, {user_id: request.user_id, search_type: search_type})}); request.put('searches/'+this.state.search['id'], search_params, function(){}); uncaught typeerror: cannot read property 'lat' of undefined(…)
so, need send array of location objects. there specific format in array of location object directly converted geometry
object on update function? here update function called on search update in ruby:
def update search = search.find(params[:id]) if search.update_attributes(search_params) render :json => {:recent => search}, :status => 200 else render :json => {:error => "could not update search."}, :status => 422 end end
and search_params is:
def search_params params.require(:search).permit( :name, :user_id, :q, :drawn_polygons #this column want updated geometry object ) end
would :drawn_polygons => rgeo::geos::capimultipolygonimpl
work? if does, format of :drawn_polygons
object need provide?
or
i need take :drawn_polygons
list of coordinates, , change rgeo::geos::capimultipolygonimpl
inside update function? if so, how it?
def update search = search.find(params[:id]) search_parameters = search_params drawn_polygons = json.parse(uri.decode(search_parameters[:drawn_polygons])) # code change search_params[:drawn_polygons] geometry object, rgeo::geos::capimultipolygonimpl search_parameters(:drawn_polygons) = drawn_polygons if search.update_attributes(search_parameters) render :json => {:recent => search}, :status => 200 else render :json => {:error => "could not update search."}, :status => 422 end end
Comments
Post a Comment