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...
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....
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...
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...
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...