From daba9e3058654027ecd3f12fd2dad8473ee9408b Mon Sep 17 00:00:00 2001 From: f Date: Wed, 31 Oct 2018 18:55:50 -0300 Subject: [PATCH] mostrar un error si no se pudo procesar la imagen --- app/models/post.rb | 9 ++++----- app/views/posts/_form.haml | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 57a07a85..d18f18a3 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -234,7 +234,7 @@ class Post i.store! v.tempfile v = i.url end - rescue CarrierWave::IntegrityError => e + rescue CarrierWave::ProcessingError, CarrierWave::IntegrityError => e v = e.message end end @@ -267,10 +267,9 @@ class Post # 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.compact.map { |i| i.split('/').to_a.count <= 1 }.any? - add_error validate: get_front_matter(tf.key) + errors = [get_front_matter(tf.key)].flatten.compact + if tf.image? && errors.map { |i| File.exist?(File.join(site.path, i)) }.none? + add_error Hash[tf.key.to_sym, errors] end end end diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index 8c99ab8e..f9c3b1ba 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -1,8 +1,10 @@ - unless @post.errors.empty? .alert.alert-danger %ul - - @post.errors.each do |_,error| - %li= error + - @post.errors.each do |key, error| + %li + %strong= @post.template_fields.find { |tf| tf.key == key.to_s }.try(:label) || key + = [error].flatten.join("\n") -# TODO seleccionar la dirección por defecto según el idioma actual - direction = @post.get_front_matter('dir') || 'ltr'