【问题标题】:Mongoid, references_one, and HTML selectMongoid、references_one 和 HTML 选择
【发布时间】:2011-03-23 14:37:30
【问题描述】:

这是我在 Rails 3 应用程序上遇到的问题...

我有一个 MedicalProfessional 模型,看起来像这样:

class MedicalProfessional
 include Mongoid::Document
 include Mongoid::Timestamps
 field :name, :type => String
 references_one :medical_specialty
end

还有一个如下所示的 MedicalSpecialty 模型:

class MedicalSpecialty
 include Mongoid::Document
 field :name, :type => String
 validates_presence_of :name
 referenced_in :medical_professional
end

在视图中,我创建了一个 HTML 选择,如下所示:

select("medical_professional", "medical_specialty", @specialties)

发布该表单时,我收到以下错误:

Medical_professionals#create 中的 NoMethodError

显示第 27 行出现的 new.html.haml:

当你没想到时,你有一个 nil 对象! 您可能期望有一个 Array 的实例。 评估 nil.map 时发生错误

第 27 行是我有“选择”的那一行。

知道这里的问题是什么吗?

【问题讨论】:

    标签: html ruby-on-rails mongoid


    【解决方案1】:

    您的表单发布失败,但失败的代码路径未分配 @specialties。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-28
      • 1970-01-01
      • 1970-01-01
      • 2018-05-16
      • 1970-01-01
      • 2010-10-25
      相关资源
      最近更新 更多