如何捕获字段更新的时间
我知道rails 中的updated_at 和created_ate。 但我感兴趣的是当更新另一个字段时更新模型中的一个字段的能力。这是我尝试过的:
在我的模型中:
protected
def update_email_sent_on_date
if self.send_to_changed?
self.date_email_delivered = DateTime.now
end
end
以及在我的代码中更新相关字段的地方:
distribution.send(:update_email_sent_on_date)
问题是,这似乎根本没有对我的数据库表做任何事情。我什至尝试删除对“send_to”的检查,但仍然没有任何结果。
我做错了什么?
I'm aware of updated_at and created_ate in rails.
But what I'm interested in is the ability to update a field within a model when another field is updated. Here's what I've tried:
in my model:
protected
def update_email_sent_on_date
if self.send_to_changed?
self.date_email_delivered = DateTime.now
end
end
and in the one place in my code that updates the field in question:
distribution.send(:update_email_sent_on_date)
the problem is, this doesn't seem to be doing anything to my db table at all. I even tried removed the check on "send_to" but still nothing.
what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
进行更改后,您不会保存它。
将方法更改为:
或者像这样调用后保存模型:
You're not saving it after you make the change.
Change the method to this:
Or save the model after calling it like so: