Created
May 23, 2011 11:09
-
-
Save jlecour/986555 to your computer and use it in GitHub Desktop.
Touch plugin for MongoMapper
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
# encoding: UTF-8 | |
module MongoMapper | |
module Plugins | |
module Touch | |
extend ActiveSupport::Concern | |
module InstanceMethods | |
def touch(key = :updated_at) | |
raise "InvalidKey" unless self.key_names.include?(key.to_s) | |
self.set(key => Time.now.utc) | |
true | |
end | |
end | |
end | |
end | |
end |
But I prefer to store Dates/Times in UTC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to Kevin Lawver from the MongoMapper Google Group (http://groups.google.com/group/mongomapper/browse_thread/thread/62faeebcb0584f47) we can do this without using the driver, but the
set
method of MongoMapper's API.