Created
April 23, 2010 09:44
-
-
Save Pavling/376389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# monkey patch gleaned from http://dev.rubyonrails.org/attachment/ticket/11394/merge_bang_errors.patch | |
module ActiveRecord | |
class Errors | |
def merge!(errors, options={}) | |
fields_to_merge = if only=options[:only] | |
only | |
elsif except=options[:except] | |
except = [except] unless except.is_a?(Array) | |
except.map!(&:to_sym) | |
errors.entries.map(&:first).select do |field| | |
!except.include?(field.to_sym) | |
end | |
else | |
errors.entries.map(&:first) | |
end | |
fields_to_merge = [fields_to_merge] unless fields_to_merge.is_a?(Array) | |
fields_to_merge.map!(&:to_sym) | |
errors.entries.each do |field, msg| | |
add field, msg if fields_to_merge.include?(field.to_sym) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment