2017-05-04 7 views
1

편집 페이지에서 GeoJSON 데이터를 텍스트로 편집 할 수있는 기능이 필요합니다. 나는 Rails, PostgreSQL과 activerecord-postgis-adapter를 사용합니다. 데이터 인코딩의 경우 rgeo-geojson을 사용합니다.레일 뷰에서 GeoJSON 데이터를 편집하는 방법은 무엇입니까?

는 내 쇼보기가 잘 작동

, 나는 인코딩 :

<%= RGeo::GeoJSON.encode(@field.shape, json_parser: :json) %> 

하지만 어떻게 내 편집보기를 업그레이드 할, 그래서 나는 GeoJSON 형식으로 데이터를 편집하고 저장할 수 :

은 if
<%= form_for :field, url: field_path(@field), method: :patch do |f| %> 
... 
    <p> 
    <%= f.label :shape %><br> 
    <%= f.text_area :shape %> 
    </p> 
... 

<% end %> 

죄송합니다 질문 엉망진창

답변

1

Field에 Postgis db 컬럼을 GeoJSON으로 변환하고 다시 변환하는 가상 속성을 추가 할 수 있습니다.

class Field < ActiveRecord::Base 
    def shape_text 
    RGeo::GeoJSON.encode(shape).to_json 
    end 

    def shape_text=(text) 
    self.shape = RGeo::GeoJSON.decode(text, json_parser: :json) 
    end 
end 


<%= form_for :field, url: field_path(@field), method: :patch do |f| %> 
... 
    <p> 
    <%= f.label :shape_text %><br> 
    <%= f.text_area :shape_text %> 
    </p> 
... 

<% end %>