new output structure for view render

This commit is contained in:
Harry Bomrah 2014-04-02 14:44:36 +08:00
parent 3847ed9a43
commit b1585a5e4c
3 changed files with 18 additions and 12 deletions

View File

@ -2,28 +2,34 @@ class AnnouncementsController < ApplicationController
def index def index
announcements = Bulletin.all announcements = Bulletin.all
announcements.collect do |a| anns = announcements.collect do |a|
{ {
"title" => a.title, "title" => a.title,
"body" => a.body, "body" => a.body,
"link_to_show" => OrbitHelper.url_to_show(a.uid,a.title.parameterize), "link_to_show" => OrbitHelper.url_to_show(a.to_param),
"more" => "More" "more" => "More",
} }
end end
{
"data" => anns
}
end end
def widget def widget
announcements = Bulletin.all announcements = Bulletin.all
announcements.collect do |a| anns = announcements.collect do |a|
{ {
"title" => a.title, "title" => a.title,
"subtitle" => a.body, "subtitle" => a.body,
"link_to_show" => OrbitHelper.url_to_show(a.uid,a.title.parameterize), "link_to_show" => OrbitHelper.url_to_show(a.to_param),
"more" => "More", "more" => "More",
"link_to_index" => "index"
} }
end end
{
"extras" => {"link_to_index" => "index","name" => "Harry"},
"data" => anns
}
end end
@ -34,5 +40,6 @@ class AnnouncementsController < ApplicationController
"title" => announcement.title, "title" => announcement.title,
"body" => announcement.body "body" => announcement.body
} }
end end
end end

View File

@ -7,11 +7,9 @@ class Bulletin
field :uid, type: String field :uid, type: String
# include Slug # include Slug
def to_param
def to_param self.title.gsub(/[ "'*@#$%^&()+=;:.,?>|\\<~_!]/,'-').gsub(/-{2,}/,'-')+'-'+self.uid
I18n.locale end
title.parameterize
end
def self.find_by_param(input) def self.find_by_param(input)
self.find_by(uid: input) self.find_by(uid: input)

View File

@ -4,6 +4,7 @@ module Announcement
OrbitApp.registration "Announcement", :type => "ModuleApp" do OrbitApp.registration "Announcement", :type => "ModuleApp" do
module_label "announcement.announcement" module_label "announcement.announcement"
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget"]
end end
end end
end end