如何在一个控制器中在红宝石上做多个更新
|
我有x和y两个模型,例如:
y.rb:
class y < ActiveRecord::Base
belongs_to :x
end
x.rb:
class X < ActiveRecord::Base
has_many :Ys
end
我的控制器将是:
x.controller.rb:
def update
@x = X.find(params[:id])
@x.update_attributes(params[:x])
@y = (params[:y])
@y.each { |t| t.attributes = params[:y][t.id.to_s] }
@x.ys.build(attributes)
flash[:notice] = \'X was successfully updated.\'
redirect_to :action => \'edit\'
end
它不会更新y数据并给出以下错误:
[\“ s \”,\“ 1233 \”]的未定义方法`attributes = \':数组
没有找到相关结果
已邀请:
2 个回复
唤副埂侧壬
看起来是一个数组数组;也就是说,对于在参数中描述的每个Y实例,都有一个单独的数组。因此,当您执行
时,您要遍历一堆数组,而不是一堆Y。
厦惫