Ruby on rails 在rails中的模型中构造关系并向其中插入数据
如何在rails 3中构建模型Ruby on rails 在rails中的模型中构造关系并向其中插入数据,ruby-on-rails,ruby,models,relationship,Ruby On Rails,Ruby,Models,Relationship,如何在rails 3中构建模型 具有一个配置文件的用户 具有一个通知的用户 具有一个角色的用户,如管理员等 我想建立他们的关系。 做了之后 如何使用一个表单一次将数据插入所有这些表。 如有任何帮助,我们将不胜感激。。 感谢您通过搜索更好地了解rails关联 user.rb has_one :profile has_one :notification has_one :role accepts_nested_attributes_for :profile, :notification, :rol
has_one :profile
has_one :notification
has_one :role
accepts_nested_attributes_for :profile, :notification, :role
您可能需要将每个“接受嵌套属性”放在它们自己的行中
相互之间的模型需要:
属于:用户
编辑
表格
= form_for @user do |f|
.field
f.text_field :name
.field
f.text_field :email
f.fields_for :profile do |t|
.field
t.text_field :description
.actions
= f.submit
此外,在控制器中,确保:
def new
@user = User.new(profile: Profile.new)
end
浏览rails和一些教程可能是,但我无法将单个表单中的数据插入所有这三个表中,因为您必须使用它