From 21aedce0eac85c548e5311bdbe882e5e31c4b7db Mon Sep 17 00:00:00 2001 From: f Date: Fri, 20 Jul 2018 13:34:33 -0300 Subject: [PATCH] poder subir varias imagenes --- app/models/post.rb | 13 ++++++++++--- app/models/post/template_field.rb | 2 +- app/views/posts/template_field/_image.haml | 5 ++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index bb82e551..fcbd3761 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -205,8 +205,15 @@ class Post if t.image? begin i = Post::ImageUploader.new(site) - i.store! v.tempfile - v = i.url + if t.multiple? + v = v.map do |tmp| + i.store! tmp.tempfile + i.url + end + else + i.store! v.tempfile + v = i.url + end rescue CarrierWave::IntegrityError => e v = e.message end @@ -234,7 +241,7 @@ class Post 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).split('/').to_a.count <= 1 + if tf.image? && [get_front_matter(tf.key)].flatten.map { |i| i.split('/').to_a.count <= 1 }.any? add_error validate: get_front_matter(tf.key) end end diff --git a/app/models/post/template_field.rb b/app/models/post/template_field.rb index e768fb60..d97cafd9 100644 --- a/app/models/post/template_field.rb +++ b/app/models/post/template_field.rb @@ -131,7 +131,7 @@ class Post end def image? - value == 'image' + array? ? value.first == 'image' : value == 'image' end # Si la plantilla es simple no está admitiendo Hashes como valores diff --git a/app/views/posts/template_field/_image.haml b/app/views/posts/template_field/_image.haml index 534adc75..1ef95b12 100644 --- a/app/views/posts/template_field/_image.haml +++ b/app/views/posts/template_field/_image.haml @@ -1,5 +1,8 @@ - if @post.url? name %img.img-fluid{src: @site.get_url_for_sutty(@post.get_front_matter(name))} +- name = [name,''] if template.multiple? = file_field_tag field_name_for_post_as_string(name), class: 'form-control', - required: template.required? + required: template.required?, + multiple: template.multiple?, + accept: 'image/*'