Do not show announcement in json and rss if no title in I18n.locale

This commit is contained in:
chris 2013-09-17 20:44:00 +08:00
parent 2d714dfa4b
commit 03189092d3
2 changed files with 23 additions and 18 deletions

View File

@ -332,18 +332,21 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
respond_to do |format| respond_to do |format|
format.json { format.json {
custom_bulletins = @bulletins.inject([]) do |data, bulletin| custom_bulletins = @bulletins.inject([]) do |data, bulletin|
deadline = bulletin.deadline.nil? ? t(:no_deadline) : display_date_time(bulletin.deadline) unless bulletin.title_translations[I18n.locale.to_s].blank?
image_url = "#{'/' unless bulletin.image.url.start_with?('/')}#{bulletin.image.url}" deadline = bulletin.deadline.nil? ? t(:no_deadline) : display_date_time(bulletin.deadline)
data << { image_url = "#{'/' unless bulletin.image.url.start_with?('/')}#{bulletin.image.url}"
title: bulletin.title, data << {
link: "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}", title: bulletin.title,
image: "#{request.protocol}#{request.host_with_port}#{image_url}", link: "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}",
category: bulletin.bulletin_category.title, image: "#{request.protocol}#{request.host_with_port}#{image_url}",
content: bulletin.text, category: bulletin.bulletin_category.title,
postdate: display_date_time(bulletin.postdate), content: bulletin.text,
deadline: deadline, postdate: display_date_time(bulletin.postdate),
tag: bulletin.sorted_tags.map{|tag| tag.name} deadline: deadline,
} tag: bulletin.sorted_tags.map{|tag| tag.name}
}
end
data
end end
render json: JSON.pretty_generate(custom_bulletins) render json: JSON.pretty_generate(custom_bulletins)
} }

View File

@ -9,12 +9,14 @@ xml.rss :version => "2.0" do
xml.link "#{request.protocol}#{request.host_with_port}#{get_bulletins_panel_announcement_back_end_bulletins_path(bulletin_category_id: @category.try(:id))}.rss" xml.link "#{request.protocol}#{request.host_with_port}#{get_bulletins_panel_announcement_back_end_bulletins_path(bulletin_category_id: @category.try(:id))}.rss"
@bulletins.each do |bulletin| @bulletins.each do |bulletin|
xml.item do unless bulletin.title_translations[I18n.locale.to_s].blank?
xml.title bulletin.title xml.item do
xml.pubDate bulletin.postdate.to_s(:rfc822) xml.title bulletin.title
xml.description bulletin.text xml.pubDate bulletin.postdate.to_s(:rfc822)
xml.link "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}" xml.description bulletin.text
xml.guid "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin)}" xml.link "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin, category_id: bulletin.bulletin_category.id, locale: I18n.locale)}"
xml.guid "#{request.protocol}#{request.host_with_port}#{panel_announcement_front_end_bulletin_path(bulletin)}"
end
end end
end end
end end