From 5987529771efe8619960e851ae05608d70302522 Mon Sep 17 00:00:00 2001 From: spen Date: Tue, 17 Jun 2014 09:51:21 +0800 Subject: [PATCH] fgu --- app/models/bulletin.rb | 9 +++++++++ .../panel/announcement/back_end/bulletins/_form.html.erb | 2 +- config/locales/en.yml | 2 ++ config/locales/zh_tw.yml | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index e8bdd98..bb2db35 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -44,6 +44,8 @@ class Bulletin validates :title, :at_least_one => true + validate :image_size + # def to_indexed_json # self.to_json # end @@ -171,5 +173,12 @@ class Bulletin # self.tag_ids.delete('') # end + def image_size + if self.image.size > 500.kilobyte + errors.add( :image, I18n.t("announcement.image_limit")) + end + end + + end diff --git a/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/app/views/panel/announcement/back_end/bulletins/_form.html.erb index 9ef3a25..6a74470 100644 --- a/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -139,7 +139,7 @@ -
<%= t("announcement.image_note")%>
+

<%= t("announcement.image_note")%>
<%= t("announcement.image_size_note")%>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 5f0bb5e..a10a566 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -28,6 +28,8 @@ en: search_result: Search result image: Cover image image_note: The image will not show in content + image_size_note: Limited to 500KB + image_limit: Image upload size is limited to 500KB link_name: Link Name new_bulletin_category: New Bulletin Category picture: Cover Picture diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 6e7509e..10279c4 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -30,6 +30,8 @@ zh_tw: search_result: 搜尋結果頁 image: 封面圖片 image_note: 此處上傳的圖片不會在公告內文出現 + image_size_note: 系統限制上傳500k以下的圖片 + image_limit: 圖片上傳容量限制為500kB link_name: 連結名稱 new_bulletin_category: 新增公告類別 picture: 刊頭圖片