假設我有兩個模型;張貼&評論接受嵌套屬性和過濾器
class Post < ActiveRecord::Base
has_many :comments
accepts_nested_attributes_for :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
before_save :do_something
def do_something
# Please, let me do something!
end
end
我有發表形式,徵求意見領域。一切都按預期工作,除了過濾器。通過上述配置,不會觸發Comment_size前的before_save過濾器。
你能解釋一下爲什麼,我該如何解決這個問題?
謝謝你的回答。但是,讓我們說,我想避免這種技術。有沒有其他方法可以達到完全相同的結果?也許在關聯上有一些參數?類似於「has_many:comments,:autosave => true」或「accep_nested_attributes_for:comments,:touch => true」? – christianblais