Today I tried to remove (actually overwrite) a validation from a model, from within a plugin.
This was the original validation:
validates_length_of :login, :maximum => 30
This was the only code I could come up with to replace it:
def self.included(base)
base.class_eval do
@validate_callbacks.delete_if { |callback|
begin
# Sorry, only way to remove validation...
# Probably tightly coupled to AR 2.3.5
(callback.method.respond_to?(:binding)) &&
(eval("attrs", callback.method.binding).first == :login) &&
(callback.options[:maximum] == 30)
rescue NameError
false
end
}
validates_length_of(:login, :maximum => 75)
end
Now in this case I could also have changed the options[:maximum] on the
callback, but either way - is there a cleaner way?
-- niklas
signature.asc
Description: This is a digitally signed message part
