ruby-on-rails-3sti

Rails 3.2 how to call before_validation for only new records


Rails 3.x before_validation(:on => :create) do does not work. Any other ideas appreciated


Solution

  • You can add a condition to the callback with:

    before_validation :do_something, :unless => Proc.new { |model| model.persisted? }