Created
February 2, 2010 04:29
-
-
Save mikeric/292376 to your computer and use it in GitHub Desktop.
MongoMapper on Edge Rails (3.0.pre)
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
# MongoMapper::Document::InstanceMethods | |
def to_model | |
errors.instance_eval do | |
def [](attribute) | |
return [] if errors[attribute.to_sym].nil? | |
errors[attribute.to_sym] | |
end | |
end | |
self | |
end |
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
# A possible solution is to define Validatable::Errors#[] in | |
# jnunemaker-validatable to always return an Array. | |
# Validatable::Errors | |
def [](attribute) | |
return [] if errors[attribute.to_sym].nil? | |
errors[attribute.to_sym] | |
end | |
# Another solution might be to set #[] to alias #raw instead of #on | |
# and make sure that #raw always returns an Array. | |
# Validatable::Errors | |
def raw(attribute) | |
return [] if errors[attribute.to_sym].nil? | |
errors[attribute.to_sym] | |
end | |
alias [] raw | |
# At this point MongoMapper::Document#to_model can be defined to | |
# just return self and everything should be working in Rails 3.0.pre | |
# and ActionPack, etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment