Ruby 在child\u模型中找不到child\u模型-rescue

Ruby 在child\u模型中找不到child\u模型-rescue,ruby,sinatra,datamapper,Ruby,Sinatra,Datamapper,我在以下模型中得到以下错误。我不知道为什么。非常感谢您的帮助 在文档中找不到事件的子\u模型文档 /usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/associations/relationship.rb:173:in“儿童救援模型” 文档模型: # encoding: utf-8 class Document include DataMapper::Resource include Paperclip

我在以下模型中得到以下错误。我不知道为什么。非常感谢您的帮助

在文档中找不到事件的子\u模型文档
/usr/local/rvm/gems/ruby-1.9.2-p180/gems/dm-core-1.1.0/lib/dm-core/associations/relationship.rb:173:in“儿童救援模型”

文档模型:

# encoding: utf-8

class Document
  include DataMapper::Resource
  include Paperclip::Resource

  timestamps :at

  property :id,                 Serial
  property :name,               String, :required => true
  property :doc_file_name,      String, :length => 255
  property :doc_content_type,   String, :length => 255
  property :doc_file_size,      Integer
  property :doc_updated_at,      DateTime
  has_attached_file :doc, :url => "/doc/:attachment/:id/:basename.:extension", :path => "#{settings.root}/public/doc/:attachment/:id/:basename.:extension"

  belongs_to :event

  validates_attachment_presence :doc
end
# encoding: utf-8
class Event
  include DataMapper::Resource
  timestamps :at

  property :id,          Serial
  property :name,        String, :required => true
  property :occuring,    DateTime, :required => true

  has n, :documents
  has n, :contacts
  has n, :users
  has n, :agendas
  has n, :questionnaires
  has n, :entries, :required => false
end
事件模型:

# encoding: utf-8

class Document
  include DataMapper::Resource
  include Paperclip::Resource

  timestamps :at

  property :id,                 Serial
  property :name,               String, :required => true
  property :doc_file_name,      String, :length => 255
  property :doc_content_type,   String, :length => 255
  property :doc_file_size,      Integer
  property :doc_updated_at,      DateTime
  has_attached_file :doc, :url => "/doc/:attachment/:id/:basename.:extension", :path => "#{settings.root}/public/doc/:attachment/:id/:basename.:extension"

  belongs_to :event

  validates_attachment_presence :doc
end
# encoding: utf-8
class Event
  include DataMapper::Resource
  timestamps :at

  property :id,          Serial
  property :name,        String, :required => true
  property :occuring,    DateTime, :required => true

  has n, :documents
  has n, :contacts
  has n, :users
  has n, :agendas
  has n, :questionnaires
  has n, :entries, :required => false
end

您在哪里调用数据映射器。完成/自动升级?听起来你好像有点鸡和蛋的问题。在调用
finalize
+
auto\u-upgrade

当前
Dir.glob(File.dirname(+/models/*'){File | require File}/DataMapper.finalize/#DataMapper.auto\u-migrate但是,如果有区别的话,我需要在DataMapper.setup之前使用模型。经过一番胡闹之后,我找到了其中的一部分,但它包括删除Dir glob并用单独的require语句替换它。也许处理dir glob加载文件的顺序?在使用绝对路径时,您必须小心,因为如果在其他地方使用相对路径,您将多次需要相同的文件。这可能会引起问题。也就是说,
需要“models/foo”
+
需要“/models/foo”
将需要foo两次。确保你知道你在哪里需要什么。除此之外,没有足够的信息来说明其他问题。希望你能让它工作起来,如果不能的话,继续简化你的代码和设置,直到它工作起来,然后追溯你的步骤,分析是什么导致了这个错误。