MongoMapper 和 Rails 3 导致未定义的方法“时间戳!”

发布于 2024-10-05 15:54:35 字数 455 浏览 3 评论 0原文

我收到错误“未定义的方法‘时间戳!’”当将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恰似旧人归 2024-10-12 15:54:35

首先,我要指出的是,如果您使用的是 Rails 3,您可能需要查看 Mongoid。它使用 ActiveModel,因此您可以使用它来完善 Rails 3。对于 2.3.x 项目,我更喜欢 MongoMapper,但在 Rails 3 项目中,Mongoid 对我来说似乎更加稳定。

也就是说,timestamps! 方法是由 Timestamps 插件提供的,它应该作为 MongoMapper::Document 包含的一部分加载。但是,您可以尝试手动包含它:

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

如果由于任何原因未加载时间戳模块,则应手动将其包含在您的模型中,并应使其可供使用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文