From fa11694ca122c5e4b8c6e27994fb75c025dd4f23 Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 16 Sep 2021 17:39:01 +0800 Subject: [PATCH] fix bug --- app/models/bulletin_file.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/bulletin_file.rb b/app/models/bulletin_file.rb index 811d1b7..01fa4fb 100644 --- a/app/models/bulletin_file.rb +++ b/app/models/bulletin_file.rb @@ -11,10 +11,12 @@ class BulletinFile field :choose_lang, :type => Array, :default => ["en","zh_tw"] field :privacy_type, type: String, default: 'public' belongs_to :bulletin - scope :to_fronted, ->(locale=I18n.locale){ self.map{|file| file.to_fronted(locale)}.compact rescue [] } + def self.to_fronted(locale=I18n.locale) + self.all.map{|file| file.to_fronted(locale)}.compact rescue [] + end def to_fronted(locale=I18n.locale) file = self - file.enabled_for?(locale) && !file[:file].blank? ? { "file_url" => "/xhr/announcements/file/#{file.id}/#{file['file']}" + "\" title=\"#{file.file_title}", + (file.enabled_for?(locale) && !file[:file].blank?) ? { "file_url" => "/xhr/announcements/file/#{file.id}/#{file['file']}" + "\" title=\"#{file.file_title}", "file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } : nil rescue nil end