ROR怎样处理关联数据库表?

ROR怎样处理关联数据库表?

一个页面表单涉及2个数据库表是,提交的时候怎么同时修改2个数据库表。
比如:

表1:people:
id
name
age

表2:mobile:
id
phonenum
people_id

表1和表2之间的关系:
people.rb
class People < ActiveRecord::Base
has_many :mobiles
end

mobile.rb
class Mobile < ActiveRecord::Base
belongs_to :people
end

在一个/views/Mobile/new.rhtml页面中怎么处理people?提交后在控制器中应该怎么做?

accepts_nested_attributes_for :people #接收参数

看一下这篇文章就可以了

http://efreedom.com/Question/1-2104737/Accepts-Nested-Attributes-Select-Tag