Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails 4 activerecord更新多个属性_Ruby On Rails_Ruby_Activerecord_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails rails 4 activerecord更新多个属性

Ruby on rails rails 4 activerecord更新多个属性,ruby-on-rails,ruby,activerecord,ruby-on-rails-4,Ruby On Rails,Ruby,Activerecord,Ruby On Rails 4,我对我试图对Rails 4/Activerecord进行的更新感到困惑。我正在使用的应用程序正在使用Stripe处理订阅,此函数应处理更新的订阅(Stripecustomer.subscription.updatedevent): 这一切似乎都很清楚,当我在rails控制台中执行单独的行时,我获得了订阅、计划等的有效数据。但是,更新并没有按预期工作。以下是rails控制台中执行的查询显示的update行: SQL (0.7ms) UPDATE "subscriptions" SET "expi

我对我试图对Rails 4/Activerecord进行的更新感到困惑。我正在使用的应用程序正在使用Stripe处理订阅,此函数应处理更新的订阅(Stripe
customer.subscription.updated
event):

这一切似乎都很清楚,当我在rails控制台中执行单独的行时,我获得了
订阅
计划
等的有效数据。但是,
更新
并没有按预期工作。以下是rails控制台中执行的查询显示的
update
行:

SQL (0.7ms)  UPDATE "subscriptions" SET "expires_at" = $1, "updated_at" = $2 WHERE "subscriptions"."id" = 23  [["expires_at", nil], ["updated_at", Wed, 07 May 2014 17:09:25 UTC +00:00]]
   (15.9ms)  COMMIT
=> true

expires\u at
nil
,第二个值
plan.id
甚至没有传递到查询中。我应该如何处理此更新?

看起来像是
事件.data.object.current\u period\u end
必须转换为
时间,如下所示:

subscription.update(expires_at: Time.at(event.data.object.current_period_end), plan_id: plan.id)
这是令人困惑的,因为在
create_subscription
事件中,我执行完全相同的更新,通过webhook数据将
expires_设置为
,并使用相同的值/时间戳将
expires_设置为


rails似乎也足够聪明,能够知道什么时候更新不会改变某个值,因此它将其排除在查询之外。这是我对
plan\u id
感到困惑的一部分--
日期的
expires\u已更改,但计划没有更改--因此rails将update语句的这一部分保留在sql之外。

您确定“event.data.object.current\u period\u end”不是零吗?此外,plan_id是否是订阅模型上的一个属性?此外,最好将计划对象分配给计划关系,并让订阅模型定义计划外键。Hi--是,
\event.data.object.current\u period\u end=1402100302
<代码>计划id是订阅上的外键。问题是stripe对计划使用的id与本地存储的不同,因此据我所知,我们必须查找它。
subscription.update(expires_at: Time.at(event.data.object.current_period_end), plan_id: plan.id)