announcement-test/app/controllers/announcements_controller.rb

54 lines
1.3 KiB
Ruby

class AnnouncementsController < ApplicationController
def index
announcements = Bulletin.can_display.order_by(:created_at=>'desc').filter_by_categories
anns = announcements.collect do |a|
{
"title" => a.title,
"subtitle" => a.subtitle,
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
"more" => "More",
}
end
{
"data" => anns
}
end
def widget
announcements = Bulletin.can_display.order_by(:created_at=>'desc').filter_by_categories
anns = announcements.collect do |a|
{
"title" => a.title,
"subtitle" => a.subtitle,
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
"more" => "More",
}
end
{
"data" => anns
}
end
def show
params = OrbitHelper.params
announcement = Bulletin.can_display.find_by(:uid=>params[:uid])
files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => file.title } }
links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => link.title } }
{
"bulletin_files" => files,
"bulletin_links" => links,
"data" => {
"title" => announcement.title,
"body" =>announcement.text,
"image" => announcement.image.url
}
}
end
end