From 1bbeefe805efba28ef9c237a1c27f3f1ce1d5dc0 Mon Sep 17 00:00:00 2001 From: hukl Date: Mon, 2 Feb 2009 23:46:46 +0100 Subject: refactored the whole tagging thing. now using acts_as_taggable_on_steroids instead of a homebrew solution --- app/helpers/content_helper.rb | 4 +++- app/models/flag.rb | 3 --- app/models/page.rb | 41 ++++------------------------------------- 3 files changed, 7 insertions(+), 41 deletions(-) delete mode 100644 app/models/flag.rb (limited to 'app') diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 3cf3488..385bca0 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -10,7 +10,7 @@ module ContentHelper begin if content =~ /]*)>/ tag = $~.to_s - matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d]*\"/) + matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d,]*\"/) matched_data.each do |data| splitted_data = data.split("=") @@ -18,6 +18,8 @@ module ContentHelper end content.sub(tag, render_collection(options)) + else + content end rescue diff --git a/app/models/flag.rb b/app/models/flag.rb deleted file mode 100644 index 6d67377..0000000 --- a/app/models/flag.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Flag < ActiveRecord::Base - has_and_belongs_to_many :pages -end diff --git a/app/models/page.rb b/app/models/page.rb index e1bddb2..5908029 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -1,39 +1,9 @@ -# Alternativ queries for the named_scope with one or two inner joins. -# Loading the Flags themselves would be another query. -# Could be faster on larger data sets. -# -# Single Join: -# -# Page.find( -# :all, -# :joins => 'JOIN flags_pages on pages.id = flags_pages.page_id', -# :include => :flags, -# :conditions => ['flags_pages.flag_id IN (?)', [1,2]] -# ) -# Two inner joins: -# -# Page.find( -# :all, -# :joins => :flags_pages, -# :conditions => ['flags_pages.flag_id IN (?)', [1,2]] -# ) -# -# Page.find_by_sql("select p.* from pages p JOIN flags_pages f on p.id = f.page_id where (f.flag_id IN (1,2))") - class Page < ActiveRecord::Base belongs_to :node - has_and_belongs_to_many :flags - - acts_as_list :column => :revision, :scope => :node_id - named_scope :with_flags, lambda {|flag_names| - if (flags = Flag.find_all_by_name(flag_names)).empty? - {} - else - {:include => :flags, :conditions => ['flags_pages.flag_id IN (?)', flags.map(&:id)] } - end - } + acts_as_taggable + acts_as_list :column => :revision, :scope => :node_id # options[:limit], - :order => "#{options[:order_by]} #{options[:order_direction]}" - ) + debugger + pages = Page.find_tagged_with(options[:flags], :match_all => true) end end \ No newline at end of file -- cgit v1.3