1
好时,所以我有这些2类HashWithIndifferentAccess保存对象的阵列
class Interface < ActiveRecord::Base
belongs_to :hardware
end
和
class Hardware < ActiveRecord::Base
has_many :interfaces
end
我有一个表格预定义@ hardware.interfaces,其包括接口的阵列,其处理如下
<%= text_field_tag "hardware[interfaces][][name]",interface.name %>
<%= text_field_tag "hardware[interfaces][][ip]",interface.ip %>
现在我尝试做...
@hardware = Hardware.find(params[:id])
@hardware.update_attributes(params[:hardware])
,并引发错误
Interface(#37298420) expected, got HashWithIndifferentAccess(#24204840)
可能有人给我介绍什么是怎么回事?以及如何解决这个问题?
也就是说怎么看正是我正在寻找的!谢谢! – Taka 2010-02-25 09:52:55
不要忘记在表单中使用interface_attributes而不是interfaces []。 – nanda 2010-02-25 11:32:45
会做。谢谢! – Taka 2010-02-26 00:20:57