![](/img/trans.png)
[英]How to update related attributes while saving objects in Rails Active Record
[英]Active Record in Rails not saving update
我有一个在活动记录中被继承的模块。
在该模块中,我调用 function 从外部源获取 id 然后更新我得到 update result = true 但记录不会保存更新的记录
# This is shared between multiple instances of classes
module External
def get_external_id
external_client_id = ExternalClient::get_id(self)
# it used to be
# self.update_attributes(external_client_id:external_client_id, external_id_updated_date: Time.now)
self.external_client_id = external_client_id
self.external_id_updated_date = Time.now
self.save
end
end
class InfomrationForm < ActiveRecord::Base
include External
end
当我尝试使用self.external_client_id
时,我会得到 null 当我应该从外部服务获取随机 UUID 时。 我检查了整个 function 服务返回一个正确的 id,我可以记录它,保存返回 true,我可以记录它,但是当我尝试使用
问题是我的一个验证在没有提出问题的情况下默默地失败了。
我必须评论所有验证,然后一一返回,以确定哪个验证失败。
验证无声无息地失败,即使它应该抛出错误。
必须注释掉所有验证并一一返回。
It was in a validation that had if: Proc.new {}
block I think the issue has to do with me calling a function in side the Proc.new and that function calls an inherited function that returns self.relation once that got fixed saving工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.