From d064a38502a73aa3fa5b451c0873b6669523fce0 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Jun 2018 15:05:35 -0300 Subject: [PATCH] convierte las tablas en arrays #51 --- app/models/post.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index c5b00cb8..6dd80b65 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -189,7 +189,16 @@ class Post def update_attributes(attrs) # el cuerpo se maneja por separado @content = attrs.delete('content') if attrs.key? 'content' - merge_with_front_matter! attrs.stringify_keys + # convertir los hashes en arrays si los campos son anidados + # usamos to_h por todos lados porque sino son + # HashWithIndifferentAccess + attrs = attrs.to_h.map do |k,v| + t = template_fields.find { |t| t.key == k } + v = v.values.map(&:to_h) if t && t.nested? && t.array? + { k => v } + end.reduce(Hash.new, :merge).stringify_keys + + merge_with_front_matter! attrs end # Requisitos para que el post sea vĂ¡lido