Skip to content
ratbeard edited this page Sep 13, 2010 · 13 revisions

What is dm-is-taggable?

It’s providing tagging support to DataMapper resources.

How to install?

  • install ‘dm-is-remixable’, if you do not have it
  • git clone git://github.com/maxime/dm-is-taggable.git
  • cd dm-is-taggable
  • sudo rake install

How to use it?

  • dependency ‘dm-is-taggable’ in your init.rb
  • In your model:

class Post
  include DataMapper::Resource

  property :id, Serial
  property :name, String
  property :description, Text

  is :taggable
end

Simple Tagging


post = Post.create(:name => "My First Post")

tasty = Tag.build('tasty')
original = Tag.build('original')

post.tag(tasty)
post.tag(original)

post.tags    #=> [tasty, original]
tasty.posts    #=> [post]
original.posts    #=> [post]

post.untag(tasty)
post.tags.reload
post.tags    #=> [original]

Taggers are tagging


class User
  include DataMapper::Resource

  property :id, Serial
  property :login, String
end

class Post
  include DataMapper::Resource

  property :id, Serial
  property :name, String
  property :description, Text

  is :taggable, :by => [User]
end

bob = User.create(:login => 'bob')
book = Book.create(:title => "Wonderful world", :isbn => "1234567890123", :author => "Awesome author")
fiction = Tag.build('fiction')
english = Tag.build('english')

bob.tag(book, :with => scifi)

bob.books #=> book
book.tags #=> scifi


Todo

  • More Specs / Testing
  • Publish on Rubyforge
  • A form helper