【发布时间】:2015-10-02 21:09:52
【问题描述】:
我有一个Tweet 模型。我想更新模型属性但不更新时间戳。
我已经阅读/尝试了一些链接,但对我不起作用:
- How to update a single attribute without touch updated_at attribute?
- http://blog.bigbinary.com/2009/01/21/override-automatic-timestamp-in-activerecord-rails.html
我试图通过在lib 目录中创建一个新文件active_record_base_patches.rb 来覆盖第二个链接中提到的ActiveRecord::Base。但是,引擎说在Tweet模型中找不到该方法。
所以,我尝试将 update_record_without_timestamping 移动到 Tweet 模型。现在找到了方法,但时间戳已更新。
有什么简单的方法可以暂时禁用 Rails 中的时间戳吗? Laravel 4 有这样的东西:https://stackoverflow.com/a/18906324/3427434.
PS:我在 Ruby 2.2.0 上使用 Ruby on Rails 4.2.3。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 activerecord