Microsoft LINQ Announced: Merging mismatches with XML, SQL Implicit Local Variables and Lambda comes to C#
Sep 13

Tagging Object Model with Rails

Ruby, Tech Add comments

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

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What are the first four letters in the word British?