From 6941f21a549eee321c84fa6e824832593a32c64e Mon Sep 17 00:00:00 2001 From: f Date: Wed, 27 Jun 2018 20:56:47 -0300 Subject: [PATCH] no fallar en articulos nuevos --- app/models/post/template_field.rb | 4 +++- app/views/posts/template_field/_select.haml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/post/template_field.rb b/app/models/post/template_field.rb index 59fabee..a535c0c 100644 --- a/app/models/post/template_field.rb +++ b/app/models/post/template_field.rb @@ -225,6 +225,8 @@ class Post # Obtiene los valores posibles para el campo de la plantilla def values + return 'false' if self.value == false + return 'true' if self.value == true # XXX por alguna razón `value` no refiere a value() :/ return '' if STRING_VALUES.include? self.value # Las listas cerradas no necesitan mayor procesamiento @@ -295,7 +297,7 @@ class Post # [ [ 1, a ], [ 2, b ] ] # aunque si no hay un : en el autocompletado, el array queda # [ [ 1, 1 ], [ 2, 2 ] ] - values = _value.last.zip _value.first + values = _value.empty? ? [] : _value.last.zip(_value.first) # En última instancia, traer el valor por defecto y ahorrarnos # volver a procesar diff --git a/app/views/posts/template_field/_select.haml b/app/views/posts/template_field/_select.haml index 2f5c1b4..1f03f48 100644 --- a/app/views/posts/template_field/_select.haml +++ b/app/views/posts/template_field/_select.haml @@ -2,6 +2,7 @@ - value = @post.get_front_matter(name.first).try(:[], name.second.to_i).try(:[], name.last) - else - value = @post.get_front_matter(template.key) +- value = [] if value.nil? - values = template.values.empty? ? value : template.values = select_tag field_name_for_post_as_string(name), options_for_select(values, value),