2

Rails3.xbefore_validation(:on => :create) doは機能しません。他のアイデアはありがたい

4

2 に答える 2

7

これは私が素晴らしい作品をしたことです。

before_validation do
  if self.new_record?      
    # do something here
  end
end
于 2013-07-15T04:27:03.693 に答える
6

次の方法でコールバックに条件を追加できます。

before_validation :do_something, :unless => Proc.new { |model| model.persisted? }
于 2012-06-04T14:56:25.120 に答える