From e5aaed952451bcca1d5ef039eb4b2c46c5a0e983 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 31 Mar 2020 17:52:41 -0300 Subject: [PATCH] guardar los valores falsos closes #141 --- app/models/metadata_boolean.rb | 12 ++++++------ app/views/posts/attributes/_boolean.haml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/metadata_boolean.rb b/app/models/metadata_boolean.rb index f0c64c4f..113b9d5f 100644 --- a/app/models/metadata_boolean.rb +++ b/app/models/metadata_boolean.rb @@ -15,14 +15,14 @@ class MetadataBoolean < MetadataTemplate # En este caso, queremos priorizar el dato enviado por le usuarie # antes que el generado internamente. def value - return false if false? + return false if self[:value] == '0' + return self[:value] unless self[:value].nil? - self[:value].present? || document.data.fetch(name.to_s, default_value) + document.data.fetch(name.to_s, default_value) end - private - - def false? - self[:value] == '0' + def save + self[:value] = !%w[0 false].include?(self[:value]) + true end end diff --git a/app/views/posts/attributes/_boolean.haml b/app/views/posts/attributes/_boolean.haml index 7814ebbe..46ab667a 100644 --- a/app/views/posts/attributes/_boolean.haml +++ b/app/views/posts/attributes/_boolean.haml @@ -1,6 +1,6 @@ .form-check = hidden_field_tag "post[#{attribute}]", '0' - = check_box_tag "post[#{attribute}]", metadata.value, metadata.value, + = check_box_tag "post[#{attribute}]", '1', metadata.value, class: "form-check-input #{invalid(post, attribute)}", aria: { describedby: id_for_help(attribute) }, autofocus: autofocus