【发布时间】:2012-11-10 01:19:49
【问题描述】:
哇 - 很多项目都包含在这个项目中,我做了一些(广泛的)搜索但无济于事,所以抛出一个耀斑,看看是否有其他人正在使用类似的堆栈并有解决方案。
我正在使用Mongoid-enabled fork of ActiveAdmin 为 Rails 3 应用程序构建管理界面。
到目前为止,ActiveAdmin(使用 Formtastic 构建其表单)似乎正在发挥作用。但是当我尝试将此堆栈与 Mongoid 的 embeds_many 和 embedded_in 关系一起使用时遇到了障碍。我正在努力成为一个好公民,并在 Mongo 中使用适当的数据建模技术,但 Formtastic 似乎不想一起玩。
我将分享我遇到的具体错误,尽管它可能很深奥。
如果我不能找到一个好的解决方案,我会接受它并使用 has_many 和 belongs_to,即使我知道我会放弃 MongoDB 的主要好处(该应用程序赢得了' 不够大,不足以让缺少连接/多个查询成为问题,但我认为我会从一开始就以正确的方式做事!)。
class Location
include Mongoid::Document
embeds_many :events
field :venue_name, type: String
end
class Event
include Mongoid::Document
embedded_in :location
field :event_name, type: String
end
ActiveAdmin.register Event do
form do |f|
f.inputs do
f.input :event_name
f.input :location, :as => :select
end
f.buttons
end
f.input :location 线路窒息并抛出:
ActionView::Template::Error (undefined method `event_id' for #<Event:0x007fa4224a20e0>):
1: insert_tag renderer_for(:new)
我将:as => :select 更改为:as => :check_boxes 并实际上让它显示正确的位置(尽管作为复选框,而不是选择或单选)。但是在提交表单后,我收到了一个问候:
Mongoid::Errors::NoParent (
Problem:
Cannot persist embedded document Event without a parent document.
)
在查看原始提交时,它试图将我的选择发送为“event_id”而不是父文档的 id(位置)。
无论如何 - 我的直觉是我正在尝试将一个方形钉子安装到一个圆孔中,但如果其他人有任何想法,他们将不胜感激。
【问题讨论】:
标签: mongodb mongoid activeadmin formtastic mongoid3