diff --git a/app/models/post/template_field.rb b/app/models/post/template_field.rb index 10f35ec..a4ad658 100644 --- a/app/models/post/template_field.rb +++ b/app/models/post/template_field.rb @@ -292,11 +292,13 @@ class Post # Si hay un subatributo, tenemos que averiguar todos los # valores dentro de el # TODO volver elegante! + # TODO volver recursivo! elsif subattr post.site.everything_of(attr, lang: collection) .compact .map { |sv| sv[subattr] } .flatten + .compact .uniq else post.site.everything_of(attr, lang: collection).compact diff --git a/app/views/posts/template_field/_select.haml b/app/views/posts/template_field/_select.haml index 19bcaa6..2bd0374 100644 --- a/app/views/posts/template_field/_select.haml +++ b/app/views/posts/template_field/_select.haml @@ -1,5 +1,5 @@ - value = [] if value.nil? -- values = template.values.empty? ? value : template.values +- values = template.values.empty? ? [value].flatten : template.values = select_tag field_name_for_post_as_string(name), options_for_select(values, value), { class: 'form-control select2', diff --git a/app/views/posts/template_field/_table.haml b/app/views/posts/template_field/_table.haml index 7e00381..dff4fe0 100644 --- a/app/views/posts/template_field/_table.haml +++ b/app/views/posts/template_field/_table.haml @@ -9,7 +9,7 @@ -# todos los que sean necesarios si estamos editando un post. -# Obtenemos todos los valores. Puede ser un Hash o un Array -# Creamos un array con un elemento solo para poder tener acceso a :each - - groups = @post.get_front_matter(template.key) + - groups = @post.get_front_matter(name) -# TODO volver a revisar cuando get_front_matter() tenga valores por defecto - groups = [{}] unless groups - if groups.is_a? Hash @@ -45,6 +45,7 @@ -# Si el campo es un array, groups es un array de hashes -# y group un hash. De lo contrarios, groups va a ser un -# Hash + -# TODO cambiar por get_front_matter - value = (template.array? || template.nested?) ? group[nf.key] : groups[nf.key] = render 'posts/template_field/nested', template: nf,