ruby-on-rails - 更新 ApplicationRecord 上的 self 属性在生产中不起作用
问题描述
导轨版本:5
我有一个这样的 ApplicationRecord 模型:
class Foo < ApplicationRecord
validates :state, presence: true
def update_state(state)
self.state = state
self.last_run_at = Time.now
if state != state_was
Rails.logger.info { "DashboardSchedule #{id} state changed from #{state_was} to #{state}"}
end
NotifyService.run(self)
if changed?
save!
end
end
end
NotifyService
定义为:
class NotifyService
def run(foo)
p foo.state
end
end
当我运行以下代码时:
a = Foo.find(1)
p a.state # "new"
a.update_state("passing")
在开发中,我会passing
在服务中打印出来。但是,在生产中,我会new
打印出来。我无法弄清楚这里可能发生了什么,如果它与将参数命名为update_state
与类属性相同的冲突有关,或者它是否是模型的一些奇怪的缓存?
解决方案
推荐阅读
- python - 在使用 odeint 求解 ODE 时查找执行时间
- javascript - 如何在下次单击数据表中的 ajax 调用时发送自定义标题?
- spring - 在 SAML SP 超时会话和 IDP 这样做之间应该发生什么?
- laravel - 是否可以在 laravel 文件管理器中为多个用户共享一个目录?
- redux - 更新 Graphql 树,不使用突变命中后端
- c++ - 运行时动态链接的 dll 中的线程退出
- markdown - 如何在 MathJax 中对齐分离的方程?
- java - 为什么 IOC 容器不调用 FactoryBean 的 getObjectType() 方法
- machine-learning - 相同的实例不同的类分类器
- swift - 如何在谷歌地图sdk中的函数之外使用变量