MongoMapper 和 Rails 3 导致未定义的方法“时间戳!”
我收到错误“未定义的方法‘时间戳!’”当将 Rails 3 与 MongoMapper 一起使用时,想知道是否有人可以帮助解决这个问题,
我正在使用 Rails 3.0.1、mongo_mapper 0.8.6 和 mongo 1.1
我的模型:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我要指出的是,如果您使用的是 Rails 3,您可能需要查看 Mongoid。它使用 ActiveModel,因此您可以使用它来完善 Rails 3。对于 2.3.x 项目,我更喜欢 MongoMapper,但在 Rails 3 项目中,Mongoid 对我来说似乎更加稳定。
也就是说,timestamps! 方法是由 Timestamps 插件提供的,它应该作为 MongoMapper::Document 包含的一部分加载。但是,您可以尝试手动包含它:
如果由于任何原因未加载时间戳模块,则应手动将其包含在您的模型中,并应使其可供使用。
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: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.