当四个模型中的三个嵌套时,是否可以从同一表单编辑不同的模型?如何?
如何处理表单中的多个模型?我知道嵌套模型存在,但我不确定这是否是相同的情况。抱歉,对 Rails 有点陌生。
就我而言,项目简介包含标题、日期、描述以及主持人等字段。然而,版主驻留在自己的模型上,并且该模型也会更新。然后是文件(名称、文件类型等)和联系人(名字、姓氏等)模型,它们也属于项目配置文件。
以下是案例中模型之间的伪关系: 项目简介有_许多版主 项目配置文件有很多文件 project_profile has_one contact
我希望能够从一张表格中编辑所有四个。这怎么可能? 谢谢!
铁轨3.0.7 红宝石 1.9.2
How do you handle multiple models in a form? I know that nested models exist, but I'm not sure if this is the same situation. Sorry, a bit new to Rails.
In my situation, a project profile has fields such as title, date, description, as well as moderators. Moderators reside on their own model however and this is also updated. Then there's the File (name, filetype, etc.) and Contact (first_name, last_name, etc.) model which also belong to a project profile.
Here are the pseudo-relations between the models in case:
project_profile has_many moderators
project_profile has_many files
project_profile has_one contact
I would like to be able to edit all four from one form. How is this possible?
Thanks!
Rails 3.0.7
Ruby 1.9.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的,它被称为
nested_attributes
。请参阅此处的教程: http:// /ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
或此处的截屏:http://railscasts.com/episodes/196-nested-model-form-part -1
It's possible, it's called
nested_attributes
.See tutorial here: http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
Or screencast here: http://railscasts.com/episodes/196-nested-model-form-part-1