Kenny Ma
Kenny Ma

Reputation: 385

MongoMapper and Rails 3 results in undefined method 'timestamps!'

I'm getting the error "undefined method 'timestamps!' when using Rails 3 with MongoMapper and was wondering if anyone can help resolve this problem.

I'm using Rails 3.0.1, mongo_mapper 0.8.6, and mongo 1.1

My model:

class User
  include MongoMapper::EmbeddedDocument         

  key :_id, String  
  key :name, String, :required => true, :limit => 100
  key :email, String, :required => false, :limit => 200
  key :bio, String, :required => false, :limit => 300

  timestamps!
end

Upvotes: 1

Views: 835

Answers (1)

Chris Heald
Chris Heald

Reputation: 62688

First off, I'll note that if you're using Rails 3, you might want to look at Mongoid. It uses ActiveModel so you get all the Rails 3 polish with it. I prefer MongoMapper for 2.3.x projects, but Mongoid has seemed much more stable for me in Rails 3 projects.

That said, the timestamps! method is provided by the Timestamps plugin, which should be loaded as a part of the MongoMapper::Document inclusion. However, you could try including it manually:

class User
  include MongoMapper::Document
  plugin MongoMapper::Plugins::Timestamps
  timestamps!
end

If the timestamps module isn't being loaded for any reason, that should manually include it in your model, and should make it available for use.

Upvotes: 3

Related Questions