I've used the gem ancestry for similar purposes. This would at least provide support in the model layer for the tree structure that you're talking about.
RailsCasts has done a tutorial about it.
To play with ancestry, I would recommend using the rails console
, for example like this:
# category.rb
class Category < ActiveRecord::Base
attr_accessor :name, :parent
has_ancestry
end
# rails console
~/Rails/CTK/jwbc[master] $ rails console
Loading development environment (Rails 3.2.11)
1.9.3p286 > main = Category.create(name: "Main category")
# => created
1.9.3p286 > sub1 = Category.create(name: "First subcategory", parent: main)
# => created
1.9.3p286 > sub2 = Category.create(name: "Sub-subcategory"), parent: sub1)
# => created
1.9.3p286 > main.children
# => Would return sub1
1.9.3p286 > main.descendants
# => Returns sub1 and sub2
1.9.3p286 > Category.at_depth(1)
# => Returns all subcategories, in this case sub1