모델 A와 모델 첨부가 있습니다. 중첩 된 특성이있는 A 양식을 다음과 같이 편집합니다. 그리고 accepts_nested_attributes_for를 통해 A에서 모든 첨부 파일을 삭제할 때 중첩 된 모든 모델에 대해 after_update/after_save 콜백을 어떻게 얻을 수 있습니까? 문제는 모델 A에서 콜백을 실행할 때 모델 A가 업데이트되고 모델 부착이 업데이트 된 후에 실행된다는 것입니다. 예를 들어, 내가 모두 삭제 한 후에 첨부 파일이 없는지를 알 수 없습니다. :) .has_many 연결, 중첩 모델 및 콜백
예를 들어 내 첨부 파일을 모두 삭제 한 후에 나의 콜백 after_save :update_status
이 제대로 작동하지 않습니다.
model A
after_save :update_status
has_many :attaches
accepts_nested_attributes_for :attaches, :reject_if => proc { |attributes| attributes['file'].blank? }, :allow_destroy => true
def update_status
print "\n\nOUPS! bag is empty!\n\n" if self.attaches.empty?
end
end
model Attach
belongs_to A
end
내가 rubyonrails.org
에서 레일 3에게 베타
좋은 통보에
A
에서 콜백 after_save 제거했지만, 내 진짜 모델 콜백에 코드 전에 지정 – fl00r