views:

169

answers:

1

Ok so I have these 2 classes

class Interface < ActiveRecord::Base
  belongs_to :hardware      
end

and

class Hardware < ActiveRecord::Base
  has_many :interfaces
end

I have a form for a predefined @hardware.interfaces which includes array of Interfaces which is handled like below

<%= text_field_tag "hardware[interfaces][][name]",interface.name %>
<%= text_field_tag "hardware[interfaces][][ip]",interface.ip %>

Now I try to do...

@hardware = Hardware.find(params[:id])
@hardware.update_attributes(params[:hardware]) 

and it throws the error

Interface(#37298420) expected, got HashWithIndifferentAccess(#24204840)

Could someone clue me in on what's going on? and how to solve this problem?

+2  A: 

update_attributes updates the model attributes.. and you are trying to update another model attributes (the Interface class)

you want to use nested form & accepts_nested_attributes_for - you can see how in this guide

amikazmi
That is exactly what I was looking for! Thanks!
Taka
Don't forget to use :interface_attributes instead of interfaces[] in your forms.
nanda
will do. thank you!
Taka