使用MongoMapper创建用于编辑嵌入式文档的表单 [英] Creating a form for editing embedded documents with MongoMapper

查看:130
本文介绍了使用MongoMapper创建用于编辑嵌入式文档的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩 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.

对于ActiveRecord,我会使用fields_for,但是在几个月前被问及是否支持该功能时, MongoMapper的作者John Nunemaker写道:不行,不行.attr_accessor的确不那么难."

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?

我对使用现有的嵌套表单实现不感兴趣,因为我想在学习MongoMapper时以常规"方式进行操作.

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.

推荐答案

在这里看看 Rails MongoMapper EmbeddedDocument表单帮助,这是一个很好的解决方案.

Take a look here Rails MongoMapper EmbeddedDocument Form Help, this is a nice solution.

这篇关于使用MongoMapper创建用于编辑嵌入式文档的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆