我正在使用 MongoMapper 但我无法弄清楚如何为嵌入的对象创建表单文件。
对于 ActiveRecord,我会使用 fields_for
但几个月前被问及是否支持时,MongoMapper 作者 John Nunemaker 写道:“不,不,使用 attr_accessor 确实没有那么难。”
好吧,很公平,但是如何编写表单才能使其发挥作用呢?
我对使用现有的嵌套表单实现不感兴趣,因为我想在学习 MongoMapper 时以“正常”方式执行此操作。
我的模型很简单 - 我有一个包含电子邮件地址、电话号码等嵌入式文档的人。我不关心更新现有的嵌入式文档。每次编辑人员时,都可以根据表单输入重新创建它们。
I'm playing around with MongoMapper but I'm having trouble figuring out how to create a form for an object that has embedded documents.
With ActiveRecord, I'd use fields_for
but when asked if this would be supported a few months ago, MongoMapper author John Nunemaker wrote: "Nope and nope. It is really [not] that hard with attr_accessor's."
OK, fair enough, but how do you write the form for this to work?
I'm not interested in using the nested form implementations that are out there because I want to do this the "normal" way as I'm learning about MongoMapper.
My model is simple enough - I've got a Person with embedded documents for email addresses, phone numbers, etc. I do not care about updating existing embedded documents. They can be re-created from the form input each time a Person is edited.
发布评论
评论(1)
看看这里Rails MongoMapper EmbeddedDocument Form Help,这是一个很好的解决方案。
Take a look here Rails MongoMapper EmbeddedDocument Form Help, this is a nice solution.