onrails.org home

Acts_as_nested_set ActiveRecord rendered with mx:Tree in Flex.

ActiveRecord: app/models/category.rb

class Category < ActiveRecord::Base
acts_as_nested_set
end

Controller: app/controllers/categories_controller.rb

class CategoriesController < ApplicationController
def index
Category.result_to_attributes_xml(Category.root.full_set)
end
end

Flex Application: ActsAsNestedSet.mxml

<?xml version=“1.0” encoding=“utf-8”?>


Result:
20071123_categories.jpg

XML generated by Category.result_to_attributes_xml(Category.root.full_set):






I used the http://wiki.rubyonrails.org/rails/pages/BetterNestedSet plugin.

Too cool!

UPDATE: The BetterNestedSet plugin doesn’t work out of the box with Rails 2.0 RC1. Thanks Joel for that info. Read more in the comment of this blog entry.

UPDATE2: Thanks Fabien, BetterNestedSet now works with Rails 2.0!

Fork me on GitHub