Permalink
Browse files

replaced unsupported acts_as_taggable with acts_as_taggable_on_steroi…

…ds, added support for multi-tag searches on top of new plugin
  • Loading branch information...
1 parent 2f00a7e commit 1c3d3679f84e0fc81694a9aa7019724d5a8f7a14 @morhekil morhekil committed Sep 2, 2008
View
@@ -0,0 +1,3 @@
+[submodule "engine_plugins/acts_as_taggable_on_steroids"]
+ path = engine_plugins/acts_as_taggable_on_steroids
+ url = git://github.com/mattetti/acts_as_taggable_on_steroids.git
@@ -56,7 +56,7 @@ def index
:conditions => cond.to_sql,
:include => :tags )
- @tags = Clipping.tags_count :user_id => @user.id, :limit => 20
+ @tags = Clipping.tag_counts :conditions => { :user_id => @user.id }, :limit => 20
@clippings_data = @clippings.collect {|c| [c.id, c.image_url, c.description, c.url ] }
@rss_title = "#{AppConfig.community_name}: #{@user.login}'s clippings"
@@ -146,14 +146,14 @@ def create
@user = current_user
@clipping = @user.clippings.new(params[:clipping])
@clipping.user = @user
-
+ @clipping.tag_list = params[:tag_list] || ''
+
respond_to do |format|
if @clipping.save!
- @clipping.tag_with(params[:tag_list] || '')
flash[:notice] = 'Clipping was successfully created.'.l
format.html {
unless params[:user_id]
- redirect_to_url(@clipping.url) rescue redirect_to user_clipping_url(@user, @clipping)
+ redirect_to @clipping.url rescue redirect_to user_clipping_url(@user, @clipping)
else
redirect_to user_clipping_url(@user, @clipping)
end
@@ -167,13 +167,13 @@ def create
# PUT /clippings/1
# PUT /clippings/1.xml
def update
- @user = User.find(params[:user_id])
+ @user = User.find(params[:user_id])
@clipping = Clipping.find(params[:id])
-
+ @clipping.tag_list = params[:tag_list] || ''
+
respond_to do |format|
@clipping.save!
if @clipping.update_attributes(params[:clipping])
- @clipping.tag_with(params[:tag_list] || '')
format.html { redirect_to user_clipping_url(@user, @clipping) }
else
format.html { render :action => "edit" }
@@ -34,8 +34,8 @@ def show
def create
@forum.attributes = params[:forum]
+ @forum.tag_list = params[:tag_list] || ''
@forum.save!
- @forum.tag_with(params[:tag_list] || '')
respond_to do |format|
format.html { redirect_to forums_path }
format.xml { head :created, :location => formatted_forum_url(:id => @forum, :format => :xml) }
@@ -44,8 +44,8 @@ def create
def update
@forum.attributes = params[:forum]
+ @forum.tag_list = params[:tag_list] || ''
@forum.save!
- @forum.tag_with(params[:tag_list] || '')
respond_to do |format|
format.html { redirect_to forums_path }
format.xml { head 200 }
@@ -28,7 +28,7 @@ def index
@photos = Photo.recent.find(:all, :conditions => cond.to_sql, :include => :tags, :page => {:current => params[:page]})
- @tags = Photo.tags_count :user_id => @user.id, :limit => 20
+ @tags = Photo.tag_counts :conditions => { :user_id => @user.id }, :limit => 20
@rss_title = "#{AppConfig.community_name}: #{@user.login}'s photos"
@rss_url = formatted_user_photos_path(@user,:rss)
@@ -106,10 +106,10 @@ def create
@photo = Photo.new(params[:photo])
@photo.user = @user
+ @photo.tag_list = params[:tag_list] || ''
respond_to do |format|
if @photo.save
- @photo.tag_with(params[:tag_list] || '')
#start the garbage collector
GC.start
flash[:notice] = 'Photo was successfully created.'.l
@@ -158,7 +158,7 @@ def swfupload
def update
@photo = Photo.find(params[:id])
@user = @photo.user
- @photo.tag_with(params[:tag_list] || '')
+ @photo.tag_list = params[:tag_list] || ''
respond_to do |format|
if @photo.update_attributes(params[:photo])
@@ -105,11 +105,11 @@ def create
@user = User.find(params[:user_id])
@post = Post.new(params[:post])
@post.user = @user
+ @post.tag_list = params[:tag_list] || ''
respond_to do |format|
if @post.save
@post.create_poll(params[:poll], params[:choices]) if params[:poll]
- @post.tag_with(params[:tag_list] || '')
flash[:notice] = @post.category ? :post_created_for_category.l_with_args(:category => Inflector.singularize(@post.category.name)) : "Your post was successfully created.".l
format.html {
if @post.is_live?
@@ -129,7 +129,7 @@ def create
def update
@post = Post.find(params[:id])
@user = @post.user
- @post.tag_with(params[:tag_list] || '')
+ @post.tag_list = params[:tag_list] || ''
respond_to do |format|
if @post.update_attributes(params[:post])
@@ -9,7 +9,7 @@ def index
@users = User.recent.vendors.find :all, :include => :tags, :page => {:current => params[:page]}
- @tags = User.tags_count :limit => 10
+ @tags = User.tag_counts :limit => 10
@active_users = User.find(:all,
:include => [:posts, :offerings],
@@ -19,33 +19,39 @@ def index
end
def show
- @tag = Tag.find_by_name(params[:id])
- if @tag.nil?
- flash[:notice] = :tag_does_not_exists.l_with_args(:tag => params[:id])
+ tag_names = params[:id]
+ @tags = Tag.find( :all, :conditions => [ 'name IN (?)', TagList.from(tag_names) ] )
+ RAILS_DEFAULT_LOGGER.debug @tags.inspect
+ if @tags.nil? || @tags.empty?
+ flash[:notice] = :tag_does_not_exists.l_with_args(:tag => tag_names)
redirect_to :action => :index and return
end
- @related_tags = @tag.related_tags
-
+ @related_tags = @tags.collect { |tag| tag.related_tags }.flatten.uniq
+ @tags_raw = @tags.collect { |t| t.name } .join(' ')
+ RAILS_DEFAULT_LOGGER.debug @tags_raw.inspect
+
if params[:type]
case params[:type]
when 'Post'
- @pages = @photos = Post.recent.tagged_with(@tag.name).find(:all, :page => {:size => 20, :current => params[:page]})
+ @pages = @posts = Post.recent.find_tagged_with(tag_names, :match_all => true, :page => {:size => 20, :current => params[:page]})
@photos, @users, @clippings = [], [], []
when 'Photo'
- @pages = @photos = Photo.recent.tagged_with(@tag.name).find(:all, :page => {:size => 30, :current => params[:page]})
- @posts, @users, @clippings = [], [], []
+ @pages = @photos = Photo.recent.find_tagged_with(tag_names, :match_all => true, :page => {:size => 30, :current => params[:page]})
+ @posts, @users, @clippings = [], [], []
when 'User'
- @pages = @users = User.recent.tagged_with(@tag.name).find(:all, :page => {:size => 30, :current => params[:page]})
+ @pages = @users = User.recent.find_tagged_with(tag_names, :match_all => true, :page => {:size => 30, :current => params[:page]})
@posts, @photos, @clippings = [], [], []
when 'Clipping'
- @pages = @clippings = Clipping.recent.find(:all, :page => {:size => 1, :current => params[:page]})
- @posts, @photos, @users = [], [], []
- end
+ @pages = @clippings = Clipping.recent.find_tagged_with(tag_names, :match_all => true, :page => {:size => 1, :current => params[:page]})
+ @posts, @photos, @users = [], [], []
+ else
+ @clippings, @posts, @photos, @users = [], [], [], []
+ end
else
- @posts = Post.recent.tagged_with(@tag.name).find(:all, :limit => 5)
- @photos = Photo.recent.tagged_with(@tag.name).find(:all, :limit => 10)
- @users = User.recent.tagged_with(@tag.name).find(:all, :limit => 10).uniq
- @clippings = Clipping.recent.tagged_with(@tag.name).find(:all, :limit => 10)
+ @posts = Post.recent.tagged_with(tag_names).find(:all, :limit => 5)
+ @photos = Photo.recent.tagged_with(tag_names).find(:all, :limit => 10)
+ @users = User.recent.tagged_with(tag_names).find(:all, :limit => 10).uniq
+ @clippings = Clipping.recent.tagged_with(tag_names).find(:all, :limit => 10)
end
end
@@ -55,8 +55,8 @@ def create
@post.topic=@topic
@post.user = current_user
# only save topic if post is valid so in the view topic will be a new record if there was an error
+ @topic.tag_list = params[:tag_list] || ''
@topic.save if @post.valid?
- @topic.tag_with(params[:tag_list] || '')
@post.save
end
if !@topic.valid?
@@ -80,8 +80,8 @@ def create
def update
@topic.attributes = params[:topic]
assign_protected
+ @topic.tag_list = params[:tag_list] || ''
@topic.save!
- @topic.tag_with(params[:tag_list] || '')
respond_to do |format|
format.html { redirect_to forum_topic_path(@forum, @topic) }
format.xml { head 200 }
@@ -46,7 +46,7 @@ def index
:page => {:current => params[:page], :size => 20}
)
- @tags = User.tags_count :limit => 10
+ @tags = User.tag_counts :limit => 10
setup_metro_areas_for_cloud
end
@@ -121,10 +121,11 @@ def update
@user.avatar = @avatar
end
+ @user.tag_list = params[:tag_list] || ''
+
if @user.save!
@user.track_activity(:updated_profile)
- @user.tag_with(params[:tag_list] || '')
flash[:notice] = "Your changes were saved.".l
unless params[:welcome]
redirect_to user_path(@user)
@@ -27,9 +27,11 @@ class Clipping < ActiveRecord::Base
def self.find_related_to(clipping, options = {})
merged_options = options.merge({:limit => 8,
- :order => 'created_at DESC',
- :sql => " AND clippings.id != '#{clipping.id}' GROUP BY clippings.id"})
- clippings = find_tagged_with(clipping.tags.collect{|t| t.name }, merged_options)
+ :order => 'created_at DESC',
+ :conditions => [ 'clippings.id != ?', clipping.id ]
+ })
+
+ find_tagged_with(clipping.tags.collect{|t| t.name }, merged_options).uniq
end
def self.find_recent(options = {:limit => 5})
View
@@ -56,8 +56,9 @@ def self.find_recent(options = {:limit => 3})
def self.find_related_to(photo, options = {})
merged_options = options.merge({:limit => 8,
:order => 'created_at DESC',
- :sql => " AND photos.id != '#{photo.id}' GROUP BY photos.id"})
- photo = find_tagged_with(photo.tags.collect{|t| t.name }, merged_options)
+ :conditions => ['photos.id != ?', photo.id]
+ })
+ photo = find_tagged_with(photo.tags.collect{|t| t.name }, merged_options).uniq
end
end
View
@@ -0,0 +1,21 @@
+require_dependency File.dirname(__FILE__) + '/../../engine_plugins/acts_as_taggable_on_steroids/lib/tag.rb'
+
+class Tag < ActiveRecord::Base
+
+ def related_tags
+ taggable_ids = self.taggings.find(:all, :limit => 10).collect{|t| t.taggable_id }
+ return [] if taggable_ids.blank?
+
+ sql = "SELECT tags.id, tags.name, count(*) AS count FROM tags
+ LEFT OUTER JOIN taggings
+ ON taggings.tag_id = tags.id
+ WHERE (taggings.taggable_id IN (#{taggable_ids.join(',')}))
+ AND tags.id != '#{self.id}'
+ GROUP BY tags.id
+ ORDER BY count DESC
+ LIMIT 10"
+
+ Tag.find_by_sql(sql)
+ end
+
+end
@@ -4,7 +4,8 @@
%h3
= params[:type] ? h(params[:type]+'s') : 'Items'
tagged:
- = link_to h(@tag.name), tag_path(@tag.name)
+ - @tags.each do |tag|
+ = link_to h(tag.name), tag_path(tag.name)
.box
%h3.tags="Related Tags".l
@@ -26,22 +27,22 @@
%li
= link_to( truncate(post.display_title, 75), user_post_path(post.user, post), :title => "by #{post.user.login}" )
%p.post_excerpt= truncate_words(post.post, 35, '...' )
- %h6.all= link_to :all_posts_tagged.l(:tag_name => @tag.name), tag_path(:id => @tag.name, :type => 'Post') unless params[:type]
+ %h6.all= link_to :all_posts_tagged.l(:tag_name => @tags_raw), tag_path(:id => @tags_raw, :type => 'Post') unless params[:type]
- if @photos.any?
%br.clear
%h3="Photos".l
- @photos.each do |photo|
= link_to image_tag(photo.public_filename(:thumb), :title => "#{photo.description} (uploaded by #{photo.user.login})", :class => "polaroid"), user_photo_path(photo.user, photo)
- %h6.all= link_to :all_photos_tagged.l(:tag_name => @tag.name), tag_path(:id => @tag.name, :type => 'Photo') unless params[:type]
+ %h6.all= link_to :all_photos_tagged.l(:tag_name => @tags_raw), tag_path(:id => @tags_raw, :type => 'Photo') unless params[:type]
- if @users.any?
.user
%h3="Users".l
- @users.each do |user|
= link_to image_tag(user.avatar_photo_url(:thumb), :class => "polaroid"), user_path(user), :title => user.login
- %h6.all= link_to :all_users_tagged.l(:tag_name => @tag.name), tag_path(:id => @tag.name, :type => 'User') unless params[:type]
+ %h6.all= link_to :all_users_tagged.l(:tag_name => @tags_raw), tag_path(:id => @tags_raw, :type => 'User') unless params[:type]
- unless @clippings.empty?
@@ -50,7 +51,7 @@
- @clippings.each do |clipping|
%a{"href"=>"#{h user_clipping_url(clipping.user, clipping) }"}
%img.polaroid.clipping{"src"=>"#{h clipping.image_uri}", "style"=>"width:108px"}
- %h6.all= link_to :all_clippings_tagged.l(:tag_name => @tag.name), tag_path(:id => @tag.name, :type => 'Clipping') unless params[:type]
+ %h6.all= link_to :all_clippings_tagged.l(:tag_name => @tags_raw), tag_path(:id => @tags_raw, :type => 'Clipping') unless params[:type]
- if @pages
.pagination= paginating_links @pages, :params => params if @pages.page_count > 1
@@ -0,0 +1 @@
+TagList.delimiter = / |\+|,/
@@ -1,5 +0,0 @@
-require 'acts_as_taggable'
-ActiveRecord::Base.send(:include, ActiveRecord::Acts::Taggable)
-
-require File.dirname(__FILE__) + '/lib/tagging'
-require File.dirname(__FILE__) + '/lib/tag'
@@ -1,4 +0,0 @@
-Acts As Taggable
-=================
-
-Allows for tags to be added to multiple classes.
Oops, something went wrong.

0 comments on commit 1c3d367

Please sign in to comment.