diff --git a/app/models/post.rb b/app/models/post.rb index 0541f664..401e6c36 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -236,12 +236,13 @@ class Post def validate add_error validate: I18n.t('posts.errors.date') unless date.is_a? Time add_error validate: I18n.t('posts.errors.title') if title.blank? + add_error validate: I18n.t('posts.errors.slug_with_path') if slug.try(:include?, '/') # XXX este es un principio de validación de plantillas, aunque no es # recursivo template_fields.each do |tf| # TODO descubrir de mejor forma que el archivo no es del formato # correcto - if tf.image? && [get_front_matter(tf.key)].flatten.map { |i| i.split('/').to_a.count <= 1 }.any? + if tf.image? && [get_front_matter(tf.key)].flatten.compact.map { |i| i.split('/').to_a.count <= 1 }.any? add_error validate: get_front_matter(tf.key) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 04ce7df7..eca51663 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -202,6 +202,7 @@ en: file: "Couldn't write the file" title: 'Post needs a title' date: 'Post needs a valid date' + slug_with_path: "The slug is the short name for the article, as shown in the URL. It can\'t contain \"/\" ;)" invalid: 'This field is required!' open: 'Tip: You can add new options by typing them and pressing Enter' private: '🔒 The values of this field will remain private' diff --git a/config/locales/es.yml b/config/locales/es.yml index 6adb44f9..029f7abb 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -198,6 +198,7 @@ es: file: 'No se pudo escribir el archivo' title: 'Necesita un título' date: 'Necesita una fecha' + slug_with_path: 'El slug es el nombre corto del artículo, tal como figura en la URL. No puede contener "/" ;)' invalid: '¡Este campo es obligatorio!' open: 'Nota: Puedes agregar más opciones a medida que las escribes y presionas Entrar' private: '🔒 Los valores de este campo serán privados'