- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有这样一个模型:
class Search
include Mongoid::Document
embeds_many :terms
accepts_nested_attributes_for :terms
end
class Terms
include Mongoid::Document
embedded_in :search, inverse_of: :terms
field :some, type: String
field :search, type: String
field :terms, type: String
end
我有一些火腿,看起来像:
= form_for @search do |f|
- f.fields_for(:terms) do |term_form|
= term_form.label :some
= term_form.text_field :some
= term_form.label :search
= term_form.text_field :search
= f.submit 'Save'
我的 Search#new 方法如下所示:
@search = Search.new
@search.terms.build
如果页面上出现任何内容,我会很高兴,但事实并非如此。
如何使用 form_for 和 fields_for 为 Mongoid embeds_many 嵌入式文档制作表单?
郑重声明,我也试过像这样的 haml:
= form_for @search do |f|
- @search.terms.each do |term|
- f.fields_for(term) do |term_form|
....
和其他一些变体,都无济于事。
最佳答案
您的表单看起来不错 - 但我注意到您的 Controller 操作中有错字。不确定这只是您问题中的错字,还是您实际应用中的错字,但是
@search.parties.build
应该是
@search.terms.build
关于ruby-on-rails - 带有 Rails fields_for 的 Mongoid embeds_many,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6917963/
有什么办法可以用embeds_many在 Ecto 没有 id/primary_key field ? 我的数据库依赖于在这个字段上有一个唯一的索引,而 ecto 自动插入键打破了这个要求。 最佳答案
尝试使用 Ecto embeds_many 进行试验,效果很好,直到我需要查询嵌入字段中的一些数据。 所以我有一个类似 product 的东西 embeds_many categories schem
我已经找了好几天都没有找到我的问题的确切答案,这个答案就这么简单:我有一个简单的模型,有书和作者。一本书嵌入了许多作者,而作者嵌入在书中。但是每当我保存一本新书时,作者数组就不会保留。 我有一个 An
我有 2 个看起来像这样的 Mongoid 模型: class User include Mongoid::Document field :name, type: String embed
如何为我的嵌入对象设置默认顺序,例如: class Post embeds_many :comments, :order => "author" accepts_nested_attribut
在 embeds_many 之间进行选择时应考虑哪些要点?和references_many (或 embeds_one 和 references_one )在 Mongoid 中? 我目前更喜欢 em
我有一个 embeds_many 关联,我正在尝试建立它,我以前已经成功地完成了它,但我正在尝试以一种嵌套形式完成这一切,但我无法弄清楚。 假设我们有一个pocket模型: class Pocket
尝试使用此 railscast 作为指南: http://railscasts.com/episodes/197-nested-model-form-part-2?view=asciicast 遇到这
使用 Rails 3.2 和 Mongoid 2.4。我有一个遗留模型 Organization,它嵌入了很多 organization_members。它看起来像这样: class Organiza
class Hotel include Mongoid::Document field :title, type: String embeds_many :comments end cla
我有两个模型,Owner 和 Property,其中 Owner 的模式有一个 embeds_many声明,像这样: defmodule MyApp.Owner do use MyApp.Web,
我的应用程序有这个事件模型。如果我创建另一个模型:日期...那么一个事件可以有多个日期,我应该使用 Events EmbedsMany Dates 吗?或者更好地使用 Events hasMany D
class Report include Mongoid::Document embeds_many :figures end class Figure include Mongoid::
我有一个嵌入了许多“SuggestedPerson”的模型“Person”。 SuggestedPerson 还引用另一个人(被建议的人)。所以 Person 需要 embed_many 和 has_
我有用于 omni-auth 身份验证的 User 模型。我已对其进行设置,以便可以使用不同的提供商(如 facebook、google 帐户)进行登录。如果在使用这些提供商注册时电子邮件已在数据库中
我有这样一个模型: class Search include Mongoid::Document embeds_many :terms accepts_nested_attributes_
我有一个 Submittable 类,其中嵌入了很多提交。我有一个 rspec 测试,我想在其中将新的提交推送到 Submittable.submissions 集合。如果我使用哈希初始化提交,它会工
我有两个模型,博客和主题。博客 embeds_many :themes 和 Theme embedded_in :blog。我也有 Blog embeds_one :theme (用于激活的主题)。这
谁能给我解释一下 embeds_many 和 has_many 在 mongoid 中的区别? 最佳答案 embeds_many 用于在父文档中存储相关文档。 has_many 用于将文档之间的关系存
哇 - 许多项目都包含在这个项目中,我做了一些(广泛的)搜索但无济于事,所以抛出一个 flare 看看是否有其他人正在使用类似的堆栈并有解决方案。 我正在使用 Mongoid-enabled fork
我是一名优秀的程序员,十分优秀!