5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-06 13:45:46 +00:00

validar que el slug no tenga /

This commit is contained in:
f 2018-07-23 12:40:37 -03:00
parent 36eb9fbe62
commit 9ab507c4f9
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
3 changed files with 4 additions and 1 deletions

View file

@ -236,12 +236,13 @@ class Post
def validate def validate
add_error validate: I18n.t('posts.errors.date') unless date.is_a? Time 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.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 # XXX este es un principio de validación de plantillas, aunque no es
# recursivo # recursivo
template_fields.each do |tf| template_fields.each do |tf|
# TODO descubrir de mejor forma que el archivo no es del formato # TODO descubrir de mejor forma que el archivo no es del formato
# correcto # 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) add_error validate: get_front_matter(tf.key)
end end
end end

View file

@ -202,6 +202,7 @@ en:
file: "Couldn't write the file" file: "Couldn't write the file"
title: 'Post needs a title' title: 'Post needs a title'
date: 'Post needs a valid date' 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!' invalid: 'This field is required!'
open: 'Tip: You can add new options by typing them and pressing Enter' open: 'Tip: You can add new options by typing them and pressing Enter'
private: '&#128274; The values of this field will remain private' private: '&#128274; The values of this field will remain private'

View file

@ -198,6 +198,7 @@ es:
file: 'No se pudo escribir el archivo' file: 'No se pudo escribir el archivo'
title: 'Necesita un título' title: 'Necesita un título'
date: 'Necesita una fecha' 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!' invalid: '¡Este campo es obligatorio!'
open: 'Nota: Puedes agregar más opciones a medida que las escribes y presionas Entrar' open: 'Nota: Puedes agregar más opciones a medida que las escribes y presionas Entrar'
private: '&#128274; Los valores de este campo serán privados' private: '&#128274; Los valores de este campo serán privados'