From 093845c8e88b1093e936d8d5cf23c31e71384c23 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 23 Jul 2020 16:06:29 -0300 Subject: [PATCH] valores de un checkbox y asegurar que los nombres de metadatos sean simbolos --- app/models/metadata_boolean.rb | 11 ++++++++++- app/models/post.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/metadata_boolean.rb b/app/models/metadata_boolean.rb index a2c9c106..5e4b456f 100644 --- a/app/models/metadata_boolean.rb +++ b/app/models/metadata_boolean.rb @@ -28,6 +28,15 @@ class MetadataBoolean < MetadataTemplate return document.data.fetch(name.to_s, default_value) if self[:value].nil? return self[:value] unless self[:value].is_a? String - self[:value] = self[:value] == '1' + self[:value] = true_values.include? self[:value] + end + + private + + # Los valores que evalĂșan a verdadero + # + # XXX: memoizamos porque Struct no puede declarar constantes. + def true_values + @true_values ||= %w[1 on true].freeze end end diff --git a/app/models/post.rb b/app/models/post.rb index 19bb306e..f05faaba 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -51,7 +51,7 @@ class Post < OpenStruct MetadataFactory.build(document: document, post: self, site: site, - name: name, + name: name.to_sym, value: args[name.to_sym], layout: layout, type: template['type'],