Skip to content

Instantly share code, notes, and snippets.

@lapluviosilla
Created August 20, 2010 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lapluviosilla/541195 to your computer and use it in GitHub Desktop.
Save lapluviosilla/541195 to your computer and use it in GitHub Desktop.
ActiveRecord::Base.class_eval do
class << self
# Ugly bit of metaprogramming to remove an existing validation
# @param type of validation. ex. :validates_uniqueness_of
# @param name of attribute to be validated. ex. :email
def remove_validation type, name
@validate_callbacks.reject! do |back|
proc = back.method
if proc.is_a?(Proc)
# Returns the name of method the proc was declared in
method = eval("caller[0] =~ /`([^']*)'/ and $1", proc.binding).to_sym rescue nil
attrs = eval("attrs", proc.binding) rescue nil
if method == type
if attrs.include?(name) && attrs.length > 1
eval("attrs.delete(#{name})", proc.binding)
false
elsif attrs.include?(name)
true
else
false
end
end
else
false
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment