ActiveRecord relationship ID change

Hi guys, I'm having a problem with a belongs_to relationship. The thing is: class Banner < ActiveRecord::Base   belongs_to :campaign   ... end

I’m pretty sure you need to pass the ID along with the attributes, otherwise Rails creates a new instance:

campaign.update_attribute(:banner_attributes, {:id => banner.id, :content => “Changed”})

instead of

campaign.update_attribute(:banner_attributes, {:content => “Changed”})

The other option would be to just update the banner directly:

campaign.banner.content = “Changed”

Yes, that's pretty much what's happening. I, actually, was a moron, since I should have see the code in first place. The update_attributes method in ActiveRecord::Base is stupidly simple and it's really clear what it does:

2666 def update_attributes(attributes) 2667 with_transaction_returning_status(:update_attributes_inside_transaction, attributes) 2668 end 2669 2670 def update_attributes_inside_transaction(attributes) #:nodoc: 2671 self.attributes = attributes 2672 save 2673 end

Duh! Sorry guys. My bad. Thanks anyway for your time, Tim.