Rails 3: How does “accepts_nested_attributes_for” work?

I think that you’re trying to figure out creating a new associated item vs. associating with an existing item.

For creating a new item, you seem to have it working.
When you passed the id in shop_attributes, it did not work, because it’s looking up an association that doesn’t exist yet.

If you’re trying to associate with an existing item, you should be using the following:

params[:product][:shop_id] = "20"

This will assign the current product’s shop to the shop with id ‘shop_id’. (Product should have a ‘shop_id’ column.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)