From b1585a5e4c65cadcd54eacd4d466966a0ac87873 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 2 Apr 2014 14:44:36 +0800 Subject: [PATCH] new output structure for view render --- app/controllers/announcements_controller.rb | 21 ++++++++++++++------- app/models/bulletin.rb | 8 +++----- lib/announcement/engine.rb | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index dacd367..ce48dab 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -2,28 +2,34 @@ class AnnouncementsController < ApplicationController def index announcements = Bulletin.all - announcements.collect do |a| + anns = announcements.collect do |a| { "title" => a.title, "body" => a.body, - "link_to_show" => OrbitHelper.url_to_show(a.uid,a.title.parameterize), - "more" => "More" + "link_to_show" => OrbitHelper.url_to_show(a.to_param), + "more" => "More", } end + { + "data" => anns + } end def widget announcements = Bulletin.all - announcements.collect do |a| + anns = announcements.collect do |a| { "title" => a.title, "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", - "link_to_index" => "index" } end + { + "extras" => {"link_to_index" => "index","name" => "Harry"}, + "data" => anns + } end @@ -34,5 +40,6 @@ class AnnouncementsController < ApplicationController "title" => announcement.title, "body" => announcement.body } - end + end + end diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index bd6658c..562da55 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -7,11 +7,9 @@ class Bulletin field :uid, type: String # include Slug - - def to_param - I18n.locale - title.parameterize - end + def to_param + self.title.gsub(/[ "'*@#$%^&()+=;:.,?>|\\<~_!]/,'-').gsub(/-{2,}/,'-')+'-'+self.uid + end def self.find_by_param(input) self.find_by(uid: input) diff --git a/lib/announcement/engine.rb b/lib/announcement/engine.rb index 4c7b94d..1b9651e 100644 --- a/lib/announcement/engine.rb +++ b/lib/announcement/engine.rb @@ -4,6 +4,7 @@ module Announcement OrbitApp.registration "Announcement", :type => "ModuleApp" do module_label "announcement.announcement" base_url File.expand_path File.dirname(__FILE__) + widget_methods ["widget"] end end end