Make sure it still works if we are working with mongo (use the old code then). We use the class-name so we do not get any issues when Mongoid is not known. Fixes #65.
This commit is contained in:
parent
a8a3328ad9
commit
37ab5dd2c5
|
@ -86,10 +86,16 @@ module Cocoon
|
|||
def create_object(f, association)
|
||||
assoc = f.object.class.reflect_on_association(association)
|
||||
|
||||
if assoc.collection?
|
||||
f.object.send(association).build
|
||||
if assoc.class.name == "Mongoid::Relations::Metadata"
|
||||
conditions = assoc.respond_to?(:conditions) ? assoc.conditions.flatten : []
|
||||
assoc.klass.new(*conditions)
|
||||
else
|
||||
f.object.send("build_#{association}")
|
||||
# assume ActiveRecord or compatible
|
||||
if assoc.collection?
|
||||
f.object.send(association).build
|
||||
else
|
||||
f.object.send("build_#{association}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue