Rails accepts_nested_attributes_for 问题

tumayun · 2012年07月10日 · 最后由 tumayun 回复于 2012年07月10日 · 3489 次阅读
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 都等不及了。。。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号