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:
nathanvda 2012-05-21 00:55:33 +02:00
parent a8a3328ad9
commit 37ab5dd2c5
1 changed files with 9 additions and 3 deletions

View File

@ -86,12 +86,18 @@ module Cocoon
def create_object(f, association) def create_object(f, association)
assoc = f.object.class.reflect_on_association(association) assoc = f.object.class.reflect_on_association(association)
if assoc.class.name == "Mongoid::Relations::Metadata"
conditions = assoc.respond_to?(:conditions) ? assoc.conditions.flatten : []
assoc.klass.new(*conditions)
else
# assume ActiveRecord or compatible
if assoc.collection? if assoc.collection?
f.object.send(association).build f.object.send(association).build
else else
f.object.send("build_#{association}") f.object.send("build_#{association}")
end end
end end
end
def get_partial_path(partial, association) def get_partial_path(partial, association)
partial ? partial : association.to_s.singularize + "_fields" partial ? partial : association.to_s.singularize + "_fields"