diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 4d06053..eb5c241 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -637,7 +637,7 @@ class AnnouncementsController < ApplicationController anns = top_anns + rest_anns end end - anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue nil } + anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') if a["postdate"] } anns end @@ -814,7 +814,7 @@ class AnnouncementsController < ApplicationController "title" => announcement.title, "subtitle_ann" => subtitle_ann, "update_user" => update_user, - "updated_at" => (announcement.postdate.in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue ""), + "updated_at" => (announcement.postdate ? announcement.postdate.in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') : ""), "body" =>announcement.text, "image" => announcement.image.url, "img_src" => img_src, @@ -878,7 +878,7 @@ class AnnouncementsController < ApplicationController OrbitHelper.render_meta_tags([{"property" => "og:title", "content" => announcement["title_translations"][locale]},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url.split("?").first},{"property" => "og:description", "content" => meta_desc},{"property" => "og:image", "content" => announcement["image"]["original"]},{"property" => "og:type", "content" => "Article"}]) - datetime = DateTime.parse(announcement["postdate"]) + datetime = announcement["postdate"] ? DateTime.parse(announcement["postdate"]) : nil bulletin_carousel_images = Array(announcement["bulletin_carousel_images"]) resume_btn_title = (I18n.locale.to_s =="zh_tw") ? "繼續播放" : "resume" diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index 3002ced..f0fa4b6 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -146,12 +146,14 @@ module AnnouncementsHelper end flag = title.include?(keywords.to_s) end - if sflag && !eflag - flag = flag && (anns.postdate<=etime) - elsif !sflag && eflag - flag = flag && (anns.postdate>=stime) - elsif !sflag && !eflag - flag = flag && (anns.postdate>=stime) && (anns.postdate<=etime) + if anns.postdate + if sflag && !eflag + flag = flag && (anns.postdate<=etime) + elsif !sflag && eflag + flag = flag && (anns.postdate>=stime) + elsif !sflag && !eflag + flag = flag && (anns.postdate>=stime) && (anns.postdate<=etime) + end end flag }