Created
April 4, 2012 05:25
-
-
Save linyows/2298000 to your computer and use it in GitHub Desktop.
This file contains 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
module Mongoid | |
module MultiParameterAttributes | |
protected | |
# Override mongoid / lib / mongoid / multi_parameter_attributes.rb | |
def instantiate_object(field, values_with_empty_parameters) | |
return nil if values_with_empty_parameters.all? { |v| v.nil? } || !field | |
values = values_with_empty_parameters.collect { |v| v.nil? ? 1 : v } | |
klass = field.type | |
if klass == DateTime || klass == Date || klass == Time | |
field.serialize(values) | |
elsif klass == String | |
klass.new values.join | |
elsif klass | |
klass.new *values | |
else | |
values | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment