Set default time value

68 views
Skip to first unread message

Elias

unread,
Apr 10, 2012, 11:31:55 AM4/10/12
to MongoMapper
Hi,

since I need to set an updated_at key manually I cant use timestamps.

So I set up the model this way

key :updated_at, Time, :default => Time.new
key :created_at, Time, :default => Time.new

Unfortunately the time value doesn't get taken from the time of saving
but from the time of launching the application which is always the
same.

Is there another way to set default timestamps?

Elias

Brian Hempel

unread,
Apr 10, 2012, 11:41:54 AM4/10/12
to mongo...@googlegroups.com
Try:

key :updated_at, Time, :default => lambda { Time.new }
key :created_at, Time, :default => lambda { Time.new }

Brian

> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en

Jamie Orchard-Hays

unread,
Apr 10, 2012, 11:43:19 AM4/10/12
to mongo...@googlegroups.com
lambda is your friend:

key :updated_at, Time, :default => lambda { || Time.new }

On Apr 10, 2012, at 11:31 AM, Elias wrote:

Reply all
Reply to author
Forward
0 new messages