The Artima Developer Community
Sponsored Link

Java Buzz Forum
Tagging Object Model with Rails

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Tagging Object Model with Rails Posted: Sep 13, 2005 5:19 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Tagging Object Model with Rails
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement
Dema has created a nice acts_as_taggable mixin that allows you to add metadata tagging to your ActiveRecord object model. Nice and clean.
class Photo < ActiveRecord::Base
  acts_as_taggable
end

photo = Photo.new

# standard tagging with a string
photo.tag 'brazil rio beach'

# tagging with an array
photo.tag ['south america', 'soccer']

# tagging with a different separator
photo.tag 'beautiful women, babes, hot chicks', :separator => ','

# tagging with a Proc separator
photo.tag '2001..2005', :separator => proc { |s| eval(s).to_a }

# suppose your tags_photos join table has attributes 
# and you want to set them while you tag
photo.tag 'samba', :attributes => { :tagged_at => Time.now }

# Let´s do some tag searching now
# Photos with soccer OR rio
Photo.find_tagged_with :any => 'soccer rio'

# Photos with beach AND women (combo tags)
Photo.find_tagged_with :all => 'beach woman'

# Using a different separator 
Photo.find_tagged_with :all => 'beach+woman', :separator => '+'

Read: Tagging Object Model with Rails

Topic: [Sep 5, 2005 13:17 PDT] 12 Links Previous Topic   Next Topic Topic: [Sep 5, 2005 03:29 PDT] 22 Links

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use