Combine custom validations with helpers

Hi

I have a model that uses several validation helpers, for example
validates_presence_of. Now I want to add a custom validate method for
a very complex validation. I override validate in the model and it
works by itself but when I do this the helper validations stop
working. I guess the helper methods rely on the
ActiveRecord::Base#validate original method in some way. Has anyone
any suggestions on how to use both a custom validate and validations
helpers?

Thanks in advance.

Erik Lindblad

Instead of overriding the validate method call validate and pass it
the name of your custom validation method. Here is an example:

class Foo < ActiveRecord::Base
  validates_presence_of :bar
  validate :ensure_some_stuff

  private
  def ensure_some_stuff
    # custom error checking here
    ....
  end
end

Aaron

Great, exactly the kind of solution I was looking for. Thanks.

/Erik