RailsGrunt

a noob working the ruby railroad.

add some comments to something?

February 23rd, 2007

What is a website without the ability to add comments to something? Well acts_as_commentable makes this really easy. Check out this thread on the ruby forum here

To install: ruby script/plugin install svn://rubyforge.org//var/svn/commentable/acts_as_commentable

In the readme there is a sample migration you will need to use, with directions on how to modify it if need be. I’m still learning how the plugins work, and do not know if there is a way to autogenerate this.

Once the migration is completed and ran, you can just add: acts_as_commentable to those objects you want to comment on and you’re all set.

Lets say you have a Person object:

class Person < ActiveRecord::Base acts_as_commentable end

Then you have a person:

p = Person.find(:first)

Create a comment:

c = Comment.new

Fill out the comment

c.name = “Name of Commentor”

c.content = “What they wrote”

then add it to your object:

p.add_comment©

to remove a comment:

p.remove_comment©