Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.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 更新Ruby块中的多个ActiveRecord对象_Ruby On Rails_Ruby_Activerecord_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 更新Ruby块中的多个ActiveRecord对象

Ruby on rails 更新Ruby块中的多个ActiveRecord对象,ruby-on-rails,ruby,activerecord,ruby-on-rails-4,Ruby On Rails,Ruby,Activerecord,Ruby On Rails 4,我试图通过迭代ActiveRecord对象列表来更新多个ActiveRecord。如何使.save方法在块内正常工作 以下是模型: class Floor < ActiveRecord::Base has_and_belongs_to_many :jobs has_many :missions, through: :jobs end class Mission < ActiveRecord::Base has_and_belongs_to_many :jobs

我试图通过迭代ActiveRecord对象列表来更新多个ActiveRecord。如何使
.save
方法在块内正常工作

以下是模型:

class Floor < ActiveRecord::Base
   has_and_belongs_to_many :jobs
   has_many :missions, through: :jobs
end

class Mission < ActiveRecord::Base
   has_and_belongs_to_many :jobs
   has_many :floors, through: :jobs
end

class Job < ActiveRecord::Base
   has_and_belongs_to_many :floor
   has_and_belongs_to_many :mission
end

而不是==使用=进行分配

mission_hash.is_eligible = mission_is_eligible(floors)
mission_hash.save
或者使用update_属性

mission_hash.update_attribute(:is_eligible, mission_is_eligible(floors))

在保存任务时,任务中是否有任何变化?尝试在保存之前触摸更新的\u-at-任务\u散列。更新的\u属性(:更新的\u-at,Time.now)更改了控制器中的此行:
mission\u散列。更新的\u属性(:is\u-qualified,mission\u-is\u-qualified(floors))
并添加了
mission\u散列。更新的\u属性(:updated\u-at,Time.now)
:更新的“”正在工作,但“”的“”可启用“”变为空。“”的数据类型是什么?它是一个枚举/布尔/整数吗?您在这里使用==分配任务\u哈希。任务\u合格==任务\u合格(楼层)它工作!任务中有一个bug。谢谢!
mission_hash.is_eligible = mission_is_eligible(floors)
mission_hash.save
mission_hash.update_attribute(:is_eligible, mission_is_eligible(floors))