It’s just data

Acts As Tree

Combining the Rails Confidence Builder and Atom’s processing model for content, and I’m nearly ready to consume some real data.  Trouble is, each feed contains both entries and comments.

The solution is acts_as_tree.  Adding the following to the DDL:

parent_id int,

And the following to class Entry:

acts_as_tree :order=>"updated"

And modifying the creation of new entries to look like this:

post = parent ? parent.children.create : Entry.new

And I’m done.  Entries can have comments, and (for future growth) comments can be nested.  Class methods root and roots are defined, as well as instance methods for creating, querying, updating, and removing both parents and children.


More from Ruby on Ruby

Sam Ruby continues to explore Ruby, this time showing how to persist entries retrieved from an Atom feed into a MySQL DB; 99 lines including database creation, table setup and feed parsing! My favorite feature is the way Ruby enables you to add...

Excerpt from Stefan Tilkov's Random Stuff at

Time for me to learn Rails

I need some spice in my programming life. After reading Sam Ruby’s most recent post about Ruby on Rails, I think it’s time for me to learn Rails. It’ll be a good exercise for me to gain some intimate knowledge of Ruby as well....

Excerpt from Keith's Weblog at

Sam Ruby: Acts As Tree

[link]...

Excerpt from del.icio.us/tag/ruby at

Sam Ruby takes Rails to Sri Lanka FOSSSL

We suspected a pattern was emerging as IBM’s Sam Ruby first at OSCON reenacted the original joke from etech, then posted about the Rails Confidence Builder, and finally combined that work with ATOM using acts_as_tree. Yes, something was in the...

Excerpt from Riding Rails at

Acts as Tree

More fun with Rails from Sam. Also check out his unit testing post if you haven’t already....

Excerpt from 106 Miles to Chicago at

Sam Ruby takes Rails to Sri Lanka FOSSSL

We suspected a pattern was emerging as IBM’s Sam Ruby first at OSCON reenacted the original joke from etech, then posted about the Rails Confidence Builder, and finally combined that work with ATOM using acts_as_tree. Yes, something was in the...

Excerpt from Riding Rails at

Archipelago News 08/26/2005

In the it’s a small world category, I went over to Rockland Lake to ride last evening. There’s apparently a Thursday evening ride of the Rockland bike club scheduled around the time I got there. I had expected to be there with my family, but my wife...

Excerpt from Archipelago Messages at

[from andexor] Sam Ruby: Acts As Tree

[link]...

Excerpt from Delicious/url/63ac69c1108ed54db016fb9d5bc4f181 at

Add your comment