From 8e53925406ab7e830664f21ec0ffd80fe044f959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Tue, 16 Nov 2021 10:14:40 +0800 Subject: [PATCH] fix bug --- app/controllers/faqs_controller.rb | 8 ++++++-- app/models/qa_file.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb index cd48465..c17706d 100644 --- a/app/controllers/faqs_controller.rb +++ b/app/controllers/faqs_controller.rb @@ -11,8 +11,10 @@ class FaqsController < ApplicationController end qa_files = qa.qa_files.map do |qa_file| next if !qa_file.enabled_for?(locale) + file = qa_file.file + next if file.path.nil? { - "file_url" => qa_file.file.url + "\" title=\"#{qa_file.file_title}", + "file_url" => file.url + "\" title=\"#{qa_file.file_title}", "file_title" => (qa_file.title.blank? ? File.basename(qa_file["file"]) : qa_file.title) } end.compact @@ -42,8 +44,10 @@ class FaqsController < ApplicationController faqs_files = faq.qa_files.collect do |f| next if !qa_file.enabled_for?(locale) + file = qa_file.file + next if file.path.nil? { - "file_url" => f.file.url + "\" title=\"#{f.file_title}", + "file_url" => file.url + "\" title=\"#{f.file_title}", "file_title" => f.title } end.compact diff --git a/app/models/qa_file.rb b/app/models/qa_file.rb index d09e114..220b397 100644 --- a/app/models/qa_file.rb +++ b/app/models/qa_file.rb @@ -16,7 +16,7 @@ class QaFile elsif self.title.present? return self.title else - return File.basename(self.file.path) + return (File.basename(self.file.path) rescue nil) end end def enabled_for?(lang)