From 7d287fe5305dc7b0d63667f251400c751c1f1459 Mon Sep 17 00:00:00 2001 From: Alinson S Xavier Date: Sat, 13 Jul 2013 23:06:12 -0400 Subject: [PATCH] acts_as_paranoid_versioned and routes --- Gemfile | 6 +++++- Gemfile.lock | 18 ++++++++++++++++++ app/helpers/wiki_helper.rb | 2 +- app/models/event.rb | 7 ++++++- app/models/message.rb | 6 +++++- app/models/wiki_page.rb | 6 +++++- config/routes.rb | 11 ++++++++++- 7 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 0333c46..d4db0c4 100644 --- a/Gemfile +++ b/Gemfile @@ -19,9 +19,13 @@ gem 'will_paginate', "~>3.0" gem 'calendar_helper', "~>0.2" gem 'shoulda', "~>2.11" gem 'acts_as_paranoid', '~>0.4' -#gem 'acts_as_versioned', '~>0.6', :ignore_dependencies => true +gem 'acts_as_versioned', :git => 'https://github.com/jwhitehorn/acts_as_versioned.git' gem 'acts_as_list', '~>0.2' group :development, :production do gem 'brazilian-rails', '3.3.0', :path => './vendor/gems/brazilian-rails/brI18n/' end + +group :development do + gem 'mongrel' +end diff --git a/Gemfile.lock b/Gemfile.lock index 3961a5f..1d2ab78 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/jwhitehorn/acts_as_versioned.git + revision: 44dfe632ba8c97c786cbc172a2da18a41b17f668 + specs: + acts_as_versioned (3.2.1) + activerecord + PATH remote: ./vendor/gems/bluecloth specs: @@ -46,6 +53,7 @@ GEM builder (3.0.4) calendar_helper (0.2.5) open4 + cgi_multipart_eof_fix (2.5.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -53,9 +61,12 @@ GEM coffee-script-source execjs coffee-script-source (1.6.3) + daemons (1.1.9) erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) + fastthread (1.0.7) + gem_plugin (0.2.3) haml (3.1.8) hike (1.2.3) hpricot (0.8.6) @@ -70,6 +81,11 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.23) + mongrel (1.1.5) + cgi_multipart_eof_fix (>= 2.4) + daemons (>= 1.0.3) + fastthread (>= 1.0.1) + gem_plugin (>= 0.2.3) multi_json (1.7.7) open4 (1.3.0) polyglot (0.3.3) @@ -127,6 +143,7 @@ PLATFORMS DEPENDENCIES acts_as_list (~> 0.2) acts_as_paranoid (~> 0.4) + acts_as_versioned! bluecloth (= 1.0.0)! brazilian-rails (= 3.3.0)! calendar_helper (~> 0.2) @@ -136,6 +153,7 @@ DEPENDENCIES icalendar (~> 1.0) jquery-rails json + mongrel rails (~> 3.2) sass-rails (~> 3.2.3) shoulda (~> 2.11) diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index 8ff7c45..d63f841 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -19,7 +19,7 @@ class String def format_wiki text = BlueCloth.new(self).to_html text = Hpricot(text, :xhtml_strict => true).to_s - return text.sanitize + return text.sanitize unless text.blank? end end diff --git a/app/models/event.rb b/app/models/event.rb index 9a1f41d..1194f79 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -20,7 +20,12 @@ class Event < ActiveRecord::Base # Plugins acts_as_paranoid acts_as_versioned :if_changed => [ :title, :description, :time ] - acts_as_paranoid_versioned + + #acts_as_paranoid_versioned + self.versioned_class.class_eval do + def self.delete_all(conditions = nil); return; end + end + self.non_versioned_columns << 'deleted_at' # Associacoes diff --git a/app/models/message.rb b/app/models/message.rb index 995dd61..0df990d 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -21,7 +21,11 @@ class Message < ActiveRecord::Base acts_as_paranoid acts_as_versioned :if_changed => [ :title, :body ] self.non_versioned_columns << 'deleted_at' - acts_as_paranoid_versioned + + #acts_as_paranoid_versioned + self.versioned_class.class_eval do + def self.delete_all(conditions = nil); return; end + end # Associacoes belongs_to :user, diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 4c9711f..fcc5e6c 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -25,7 +25,6 @@ class WikiPage < ActiveRecord::Base acts_as_paranoid acts_as_list :scope => 'course_id = #{course_id}' acts_as_versioned :if_changed => [ :content, :description, :title ] - acts_as_paranoid_versioned self.non_versioned_columns << 'front_page' self.non_versioned_columns << 'position' self.non_versioned_columns << 'deleted_at' @@ -43,6 +42,11 @@ class WikiPage < ActiveRecord::Base validates_uniqueness_of :canonical_title, :scope => :course_id validates_format_of :title, :with => /^[^0-9]/ + # acts_as_paranoid_versioned + self.versioned_class.class_eval do + def self.delete_all(conditions = nil); return; end + end + def before_validation self.canonical_title = self.title.pretty_url end diff --git a/config/routes.rb b/config/routes.rb index 6470069..dcf3bc8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +ActiveSupport::Inflector.inflections do |inflect| + inflect.irregular 'wiki_instance', 'wiki' + inflect.irregular 'news_instance', 'news' +end + WikiUFC::Application.routes.draw do resources :users @@ -55,7 +60,11 @@ WikiUFC::Application.routes.draw do end # Log - #match 'controllerlog' => '#index', :as => :with_options + with_options :controller => 'log' do |log| + log.match 'courses/:course_id/log', :action => 'index', :format => 'html', :as => 'course_log' + log.match 'courses/:course_id/log/:id/undo', :action => 'undo', :format => 'html', :as => 'undo_course_log' + log.match 'courses/:course_id/log.:format', :action => 'index', :as => 'formatted_course_log' + end # Services match 'services/preview' => 'wiki#preview', :as => :preview