From 02e4df8b1f035d9f17a4d3c3d2d139c222dadc82 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Sun, 15 Sep 2019 14:35:23 +0800 Subject: [PATCH] delete the empty file when user is in show-page --- app/controllers/announcements_controller.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index de4cf04..63ac875 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -76,7 +76,7 @@ class AnnouncementsController < ApplicationController end files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] files.delete(nil) - links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] + links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] author = User.find(a.create_user_id).member_profile.name rescue "" desc = a.image_description desc = (desc.nil? || desc == "" ? "announcement image" : desc) @@ -322,7 +322,11 @@ class AnnouncementsController < ApplicationController } } rescue [] files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } if file.enabled_for?(locale) } rescue [] files.delete(nil) - + files.each do |file| + if file["file_url"] =="" || file["file_url"] == nil + files.delete(file) + end + end links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] update_user = announcement.update_user.member_profile.name rescue "" desc = announcement.image_description @@ -371,7 +375,12 @@ class AnnouncementsController < ApplicationController files = announcement["bulletin_files"].map{|file| { "file_url" => file["url"], "file_title" => (file["title_translations"][locale] == "" ? URI.unescape(File.basename(file["url"])) : file["title_translations"][locale] rescue '') } } rescue [] - links = announcement["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale] == "" ? link["url"] : link["title_translations"][locale]) } } rescue [] + files.each do |file| + if file["file_url"] =="" || file["file_url"] == nil + files.delete(file) + end + end + links = announcement["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale] == "" ? link["url"] : link["title_translations"][locale]) } } rescue [] update_user = announcement["author"] desc = announcement["image_description_translations"][locale] rescue ""