Flowdock
validate() protected

Overwrite this method for validation checks on all saves and use Errors.add(field, msg) for invalid attributes.

Show source
Register or log in to add new notes.
June 25, 2009
1 thank

Validate() is run always before one of the more specific validation methods

I did not see this mentioned explicitly anywhere.

The method validate is run always before a call to validate_on_create or validate_on_update is made.

Example:

class Foo < ActiveRecord::Base
  def validate
    puts 'In validate'
  end

  def validate_on_create
    puts 'In validate_on_create'
  end

  def validate_on_update
    puts 'In validate_on_update'
  end
end

Now, when creating a new Foo using script/console, the output is as follows:

In validate
In validate_on_create

and when updating a Foo, the output looks like:

In validate
In validate_on_update