Skip to content

Instantly share code, notes, and snippets.

@adamaig
Forked from anonymous/gist:223815
Created November 2, 2009 00:20
Show Gist options
  • Select an option

  • Save adamaig/223816 to your computer and use it in GitHub Desktop.

Select an option

Save adamaig/223816 to your computer and use it in GitHub Desktop.
class Tag < ActiveRecord::Base
belongs_to :taggable, :polymorphic => true
validates_uniqueness_of :tag, :scope => [:taggable_type, :taggable_id]
def self.tag_with(owner_object, *tags)
(tags - owner_object.tags.collect {|x| x.tag}).collect do |tag|
Tag.create( :taggable => owner_object, :tag => tag )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment