From eca5ae8a98d3a9f328037666ea00aceeaa64efb6 Mon Sep 17 00:00:00 2001 From: bohung Date: Wed, 24 Mar 2021 18:16:04 +0800 Subject: [PATCH] Update description. --- app/controllers/faqs_controller.rb | 4 ++-- app/models/qa_file.rb | 10 +++++++++- app/views/admin/faqs/_form.html.erb | 2 +- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb index e9e0ca2..79db80b 100644 --- a/app/controllers/faqs_controller.rb +++ b/app/controllers/faqs_controller.rb @@ -10,7 +10,7 @@ class FaqsController < ApplicationController end qa_files = qa.qa_files.map do |qa_file| { - "file_url" => qa_file.file.url, + "file_url" => qa_file.file.url + "\" title=\"#{qa_file.file_title}", "file_title" => (qa_file.title.blank? ? File.basename(qa_file["file"]) : qa_file.title) } end @@ -39,7 +39,7 @@ class FaqsController < ApplicationController faqs_files = faq.qa_files.collect do |f| { - "file_url" => f.file.url, + "file_url" => f.file.url + "\" title=\"#{f.file_title}", "file_title" => f.title } end diff --git a/app/models/qa_file.rb b/app/models/qa_file.rb index 30b694e..f248259 100644 --- a/app/models/qa_file.rb +++ b/app/models/qa_file.rb @@ -10,5 +10,13 @@ class QaFile field :title, localize: true belongs_to :qa - + def file_title + if self.description.present? + return self.description + elsif self.title.present? + return self.title + else + return File.basename(self.file.path) + end + end end diff --git a/app/views/admin/faqs/_form.html.erb b/app/views/admin/faqs/_form.html.erb index 5b3409e..b192f40 100644 --- a/app/views/admin/faqs/_form.html.erb +++ b/app/views/admin/faqs/_form.html.erb @@ -142,7 +142,7 @@
- +
<%= t("qa.file_description_hint") %>
<% if @qa && !@qa.qa_files.blank? %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 3baaa04..c79ad06 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,6 +20,7 @@ en: answer: Answer update_user: Last modified qa: + file_description_hint: 'File Description will display in the title of file link.(When placing mouse on the link,the title will display)' create_qa_category_success: FAQ category was successfully created editing_web_resource: Editing FAQ list_of_web_resource: FAQ list diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 2fb8a51..d0445f8 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -23,3 +23,4 @@ zh_tw: list_of_web_resource: 問與答列表 new_web_resource: 新增問與答 update_qa_category_success: 問與答已成功更新 + file_description_hint: '檔案描述將會顯示在前台檔案連結的title(把滑鼠放在連結上會出現的文字)'