私は Rails フレームワークの初心者なので、素朴な質問をお許しください。google.maps.Data.MultiPolygon
データベースに保存したいオブジェクトがフロントエンドにあります。テーブルは、ユーザーが検索するたびに新しいエントリを作成します。そこには、ユーザーが特定の検索でポリゴンを描画すると更新されるsearches
datatype の別の列を追加したさまざまな列が含まれています。そのため、 call:geometry
を使用しているデータベース内の検索エントリを更新する必要があります。オブジェクトをシリアル化できないため、put 呼び出しでオブジェクトput
全体を送信できません(この問題は、ここで直面している問題と同じです)。google.maps.Data.MultiPolygons
$.params()
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(…)
そのため、位置オブジェクトの配列を送信する必要があります。この位置オブジェクトの配列がgeometry
更新関数でオブジェクトに直接変換される特定の形式はありますか? ruby での検索更新時に呼び出される update 関数は次のとおりです。
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
そして、search_params は次のとおりです。
def search_params
params.require(:search).permit(
:name,
:user_id,
:q,
:drawn_polygons #This is the column I want to be updated with geometry object
)
end
何かうまくいき:drawn_polygons => RGeo::Geos::CAPIMultiPolygonImpl
ますか?存在する場合、どの形式の:drawn_polygons
オブジェクトを提供する必要がありますか?
また
を座標のリストとして取得し、更新関数内:drawn_polygons
で変更する必要がありますか? RGeo::Geos::CAPIMultiPolygonImpl
もしそうなら、それを行う方法は?
def update
search = Search.find(params[:id])
search_parameters = search_params
drawn_polygons = JSON.parse(URI.decode(search_parameters[:drawn_polygons]))
# Some code to change the search_params[:drawn_polygons] to geometry object, specifically 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