OSDN Git Service

fix:element remove func failed
[pettanr/pettanr.git] / lib / peta / element_nestable_content.rb
index 2399998..df9884b 100644 (file)
@@ -21,6 +21,17 @@ module Peta
     
     # Class Methods
     
+    def self.permit_attributes default_permit_attributes = []
+      attrs = super
+      self.child_models.each do |element_model|
+        name = self.my_manifest.associations.child_element_name(element_model) + '_attributes'
+        child_attrs = {}
+        child_attrs[name] = element_model.permit_attributes(default_permit_attributes)
+        attrs.push child_attrs
+      end
+      attrs
+    end
+    
     # Instance Methods
     
     def boosts level
@@ -31,20 +42,22 @@ module Peta
     end
     
     def post_attributes opt = {}
-      attr = self.copy_attributes
-      hash = {}
+      attr = self.copy_attributes(opt)
+      associations_attr = {}
       self.class.child_models.each do |element_model|
         name = self.class.my_manifest.associations.child_element_name(element_model) + '_attributes'
-        hash[name] ||= {}
-        e=   self.class.child_models.map {|element_model|
-          self.element_items element_model
-        }.flatten
-
-        e.each do |element|
-          hash[name][element.post_attribute_key] = element.post_attributes opt
+        if self.class.my_manifest.associations.has_one?(element_model)
+          e = self.element_items(element_model).post_attributes(opt)
+        else
+          e = {}
+          self.element_items(element_model).each do |element|
+            e[element.post_attribute_key] = element.post_attributes(opt)
+          end
         end
+        associations_attr[name] = e
       end
-      attr.merge hash
+      attr.merge! associations_attr
+      attr
     end
     
   end