Rails accepts_nested_attributes_for 问题

tumayun · July 10, 2012 · Last by tumayun replied at July 10, 2012 · 3489 hits
class Shop < ActiveRecord::Base
has_one :tour_around
accepts_nested_attributes_for :tour_around
...
end

shop更新的时候tour_around是会被重新创建的, 而不是无则创建,有则更新,这是为什么? 以前一直没怎么用过accepts_nested_attributes_for 今天试下竟然出问题了,求科普

如何更新的? 有没有带上tour_around的 id?

额,没有带上,需要带上 id 才行么?跟据 shop_id 也是可以知道应该更新还是创建的啊, 嗯,还是需要去看看源码,一切求知于源码。 @zhangyuan 哈哈,你还没去香港啊,hanqing 都等不及了。。。

You need to Sign in before reply, if you don't have an account, please Sign up first.