Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Rails 3.xbefore_validation(:on => :create) do不工作。任何其他想法表示赞赏
before_validation(:on => :create) do
这就是我做得很好的作品。
before_validation do if self.new_record? # do something here end end
您可以使用以下方法向回调添加条件:
before_validation :do_something, :unless => Proc.new { |model| model.persisted? }