Creating a form for editing embedded documents with MongoMapper

冷暖自知 提交于 2019-12-08 20:48:45

问题


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:


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



来源:https://stackoverflow.com/questions/2480165/creating-a-form-for-editing-embedded-documents-with-mongomapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!