Mongoid, references_one, and HTML select
Here's a problem I'm having on a Rails 3 app...
I have a MedicalProfessional model th开发者_C百科at looks kind of like this:
class MedicalProfessional
include Mongoid::Document
include Mongoid::Timestamps
field :name, :type => String
references_one :medical_specialty
end
and a MedicalSpecialty model that looks like this:
class MedicalSpecialty
include Mongoid::Document
field :name, :type => String
validates_presence_of :name
referenced_in :medical_professional
end
In a view, I create an HTML select like so:
select("medical_professional", "medical_specialty", @specialties)
When posting that form, I'm getting the following error:
NoMethodError in Medical_professionals#create
Showing new.html.haml where line #27 raised:
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.map
Line #27 is the one where I have the "select".
Any idea what the issue here is?
Your form post is failing, but the failed code path does not assign @specialties.
精彩评论