0
我正在使用accepts_nested_attributes_for
和:allow_destroy => true
。被摧毀?返回零而不是真
當刪除一個對象,我可以看到屬性_destroy
被標記爲true
,但是當我檢查我的對象與object.destroyed?
,我越來越nil
,而不是true
。
任何想法爲什麼?
我正在使用accepts_nested_attributes_for
和:allow_destroy => true
。被摧毀?返回零而不是真
當刪除一個對象,我可以看到屬性_destroy
被標記爲true
,但是當我檢查我的對象與object.destroyed?
,我越來越nil
,而不是true
。
任何想法爲什麼?
從doc:
現在,當您添加_destroy關鍵屬性散列,以計算結果爲true值,你會破壞相關的模型:
member.avatar_attributes = {:id =>'2',:_destroy =>'1'} member.avatar.marked_for_destruction? #=>真
destroyed?
在這裏檢查對象實際上是銷燬:
foo = Foo.first
foo.destroyed #=> false
foo.destroy
foo.destroyed? #=> true
感謝您的快速答覆。我的問題是,我從GUI中刪除了這個值,然後這個屬性被標記爲「_destroy = true」,我的問題是如何在屬性下找到它?因爲當我試圖檢查被毀壞?它返回無 – judith
它寫在我的答案:marked_for_destruction? – apneadiving
我在marked_for_destruction上遇到了異常?方法marked_for_destruction存在,但是這種方法將對象標記爲破壞 – judith