-1
중첩 된 필드의 두 수준으로 모델을 업데이트하는 중 문제가 발생했습니다. 올바른 값을 올바르게 개체를 업데이트 할 콘솔 : (travels_attributes => {...}) 내가 flight.update_attributes를 호출 할 때 개체를 업데이트 할 때 중첩 된 특성이 저장되지 않습니다.
내가
지금 아주 간단한 모델class Flight < Plan
attr_accessible :travels_attributes
has_many :travels, :class_name => "FlightTravel", :foreign_key => "plan_id", :dependent => :destroy
accepts_nested_attributes_for :travels, :allow_destroy => true
End
class FlightTravel < ActiveRecord::Base
attr_accessible :segments_attributes
has_many :segments, :class_name => "FlightSegment", :dependent => :destroy, :foreign_key => "flight_travel_id"
accepts_nested_attributes_for :segments, :allow_destroy => true
end
class FlightSegment < ActiveRecord::Base
end
있습니다.
나는 flight.save를 호출하고 아무 것도하지 않으며, 어떤 이유로 든 중첩 된 연결을 업데이트하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까 ?
실패 할 수있는 유효성 검증이 있습니까? 아마도 단순화 된 데이터로 인해 실패한 실제 통화를 보는 데 도움이됩니다. 콘솔에서 update_attributes를 호출하면 데이터베이스에 저장해야합니다. 나는 다음과 같이 가정한다 : travel_attributes [sic]는 키가 오타이다. – austinfromboston
죄송하지만 travels_attributes가 있어야합니다. 업데이트했습니다. 아니요, 유효성 검사가 아닙니다. 왜냐하면 FlightSegment 클래스의 before_validation 콜백을 수행하지 않기 때문입니다 –
레일 콘솔에서 이것을 수행 한 다음 #save 후에 flight.errors가 비어 있는지 확인할 수 있습니까? –