1

배열 [lng, lat] 인 "location"필드가 있습니다.ActiveAdmin 및 Mongoid 3.x에서 사용자 정의 필드 (배열)를 저장할 수 없습니다.

def latitude 
    location[1] 
end 

def longitude 
    location[0] 
end 

양식은 다음과 같습니다 위도와 경도 내 모델에서 두 게터을 정의를 얻기 위해

f.inputs :name => "Location" do 
    f.input :latitude 
    f.input :longitude 
end 

을 다음과 같이

나는 정의 ActiveAdmin을 형태로 두 개의 입력 필드를 가지고 예상대로 표시됩니다. 이러한 메소드가 호출 제출하지만, 값이 유지되지 않습니다 형태 후 모델

def latitude=(lat) 
    self[:location][1] = lat.to_f 
end 

def longitude=(lon) 
    self[:location][0] = lon.to_f 
end 

에 내가 두 세터를 생성 한 그 값을 저장하기 위해

.

내가 무엇인가 놓친가요?

답변

0

해결책을 찾았습니다. set()을 사용하면 효과가있었습니다. 저장하고 update_attribute -하지 않았습니다.

def latitude=(lat) 
    self[:location][1] = lat.to_f 
    self.set :location, self[:location] 
end 

def longitude=(lon) 
    self[:location][0] = lon.to_f 
    self.set :location, self[:location] 
end