Validate_on_destroy?

What’s the best way to validate_on_destroy. Rails only seems to include
validate_on_create and validate_on_update methods. I don’t want to
resort to doing:
before_destroy do |j|
raise “There is an error” if j.etc
end
Is there a way of finding out what action (create/update/destroy) is
being performed if I use the ‘validate’ method?

On 12/7/06, Alex MacCaw [email protected] wrote:

What’s the best way to validate_on_destroy. Rails only seems to include
validate_on_create and validate_on_update methods. I don’t want to
resort to doing:
before_destroy do |j|
raise “There is an error” if j.etc
end
Is there a way of finding out what action (create/update/destroy) is
being performed if I use the ‘validate’ method?

The best approach is to use callbacks:

class Model < ActiveRecord::Base
before_destroy :on_destroy_validation_method
end

This is usually useful to clean assocciated data or something like that.

Just return false from a before_destroy callback or the before_destroy
method on the model.

-Jonathan.