Skip to content

Instantly share code, notes, and snippets.

@mikeric
Created February 2, 2010 04:29
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 mikeric/292376 to your computer and use it in GitHub Desktop.
Save mikeric/292376 to your computer and use it in GitHub Desktop.
MongoMapper on Edge Rails (3.0.pre)
# 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
# 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