From b303e8256a5548abac9003df8ea3a32985c6eaaf Mon Sep 17 00:00:00 2001 From: nccu Date: Mon, 12 Jan 2015 14:40:36 +0800 Subject: [PATCH] fix news image description --- app/controllers/news_controller.rb | 14 ++++++++++++++ app/models/news_bulletin.rb | 1 + app/views/admin/news/_form.html.erb | 12 ++++++++++-- config/locales/zh_tw.yml | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 19b15e3..16e66e3 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -61,6 +61,12 @@ class NewsController < ApplicationController } end anns = news.collect do |a| + if a.image_description.nil? + image_description = "裝飾性圖片" + else + image_description = a.image_description + end + statuses = a.statuses_with_classname.collect do |status| { "status" => status["name"], @@ -75,6 +81,7 @@ class NewsController < ApplicationController "postdate" => a.postdate.strftime('%Y-%m-%d'), "link_to_show" => OrbitHelper.url_to_show(a.to_param), "img_src" => a.image.thumb.url || "/assets/news_default_image.jpg", + "img_description" => image_description, "more" => t(:more_plus) } end @@ -114,6 +121,12 @@ class NewsController < ApplicationController categories.unshift({"name" => t("news.all"), "category-link" => "/#{I18n.locale.to_s + page.url}/"}) anns = news.collect do |a| + if a.image_description.nil? + image_description = "裝飾性圖片" + else + image_description = a.image_description + end + statuses = a.statuses_with_classname.collect do |status| { "status" => status["name"], @@ -128,6 +141,7 @@ class NewsController < ApplicationController "postdate" => a.postdate, "link_to_show" => OrbitHelper.widget_item_url(a.to_param), "img_src" => a.image.thumb.url || "/assets/news_default_image.jpg", + "img_description" => image_description } end { diff --git a/app/models/news_bulletin.rb b/app/models/news_bulletin.rb index 28c67ac..2d884b2 100644 --- a/app/models/news_bulletin.rb +++ b/app/models/news_bulletin.rb @@ -24,6 +24,7 @@ class NewsBulletin field :rejected, :type => Boolean, :default => false field :rejection_reason field :is_preview, :type => Boolean, :default => false + field :image_description, localize: true field :email_id field :email_sent, :type => Boolean, :default => false diff --git a/app/views/admin/news/_form.html.erb b/app/views/admin/news/_form.html.erb index 9470e2d..b540f1a 100644 --- a/app/views/admin/news/_form.html.erb +++ b/app/views/admin/news/_form.html.erb @@ -165,9 +165,17 @@ - + <% @site_in_use_locales.each do |locale| %> + <%= f.fields_for :image_description_translations do |f| %> +
+ +
+ <%= f.text_field locale, value: (@news_bulletin.image_description_translations[locale.to_s] rescue nil) %> +
+
+ <% end %> + <% end %> - diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 97ca238..76ec546 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -89,3 +89,4 @@ zh_tw: mail_source: 來源 mail_time: 時間 image_upload_size_note: 建議檔案小於%{image_upload_size} + image_description: 圖片描述