作者kewang (617公车)
看板Ruby
标题[问题] accepts_nested_attributes_for and belongs_to
时间Sun Sep 11 23:16:49 2011
环境:
Ruby 1.9.2, Rails 3.1.0
状况:
Migration:
User(name, laptop_id)
Laptop(serial, color, lcd_size)
Model:
User Model =>
belongs_to :laptop
accepts_nested_attributes_for :laptop
Laptop Model => has_many :users
大家好,继前两天的问题之後,现在我又有一个问题。
就是我在做User的CRUD时,必须要同时做Laptop的CRUD,所以我在User Model
加上了accepts_nested_attributes_for。依照正常用法,应该是要加在
has_many上面,但是因为我不会开放Laptop独立做CRUD,所以都是在User做CRUD
。可是我用了下面的三种方式,都试不出来。所以不知道有没有神人可以帮忙看
一下这个问题呢?感恩。
附录:
http://0rz.tw/brBTn
http://0rz.tw/DEr9B
http://0rz.tw/LDFGP
--
杂七杂八的kewang部落格
http://kewang.tw
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 221.120.2.242