铁轨 + MongoMapper +嵌入式文档表单帮助
我正在开发一个非常简单的 Web 应用程序(著名的最后一句话),并且正在使用 Rails 2.3.5 + MongoMapper 0.7.2 并使用嵌入式文档。我有两个问题要问:
首先,是否有使用 Rails + MongoMapper + EmbeddedDocument 的示例应用程序?最好在 GitHub 或其他类似网站上,这样我就可以查看源代码并了解我应该去哪里?如果不是……
完成这项任务的最佳方法是什么?我将如何创建一个表单来处理嵌入文档。
我试图做的是向用户添加地址。如果你愿意的话,我可以把这两个模型扔掉。
感谢您的帮助!
I am working on a pretty simple web application (famous last words) and am working with Rails 2.3.5 + MongoMapper 0.7.2 and using embedded documents. I have two questions to ask:
First, are there any example applications out there using Rails + MongoMapper + EmbeddedDocument? Preferably on GitHub or some other similar site so that I can take a look at the source and see where I am supposed to head? If not ...
... what is the best way to approach this task? How would I go about creating a form to handle an embedded document.
What I am attempting to do is add addresses to users. I can toss up the two models in question if you would like.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我在我的一个应用程序中采用的基本方法。问题有很多答案 - 问题是文档,答案是嵌入文档。您可以使用“添加答案”链接生成另一个答案字段,并使用“删除”链接删除一个答案字段。
_form.html.erb:
_answer.html.erb:
issues_helper.rb
我删除了一些实现的小部分,但这应该可以工作。
Here's the basic approach I took in one of my apps. Problem has many answers - problem is a document, answer is an embedded document. You can use the "add answer" link to generate another answer field, and the "remove" link to delete one.
_form.html.erb:
_answer.html.erb:
problems_helper.rb
I cut out a couple minor bits of the implementation, but that should work.
现在更容易了——更新 Rails 4.1.1、ruby 2.1.1p76:
模型:
控制器:
new.html.erb:
Even easier now -- update for Rails 4.1.1, ruby 2.1.1p76:
Models:
Controller:
new.html.erb: