Hi,

I have a model called "ProductAttribute":

class ProductAttribute < ActiveRecord::Base
  belongs_to :product
  has_many :children,   :foreign_key => :parent_id, :class_name =>
'ProductAttribute', :dependent => :destroy, :order => :position
  belongs_to :parent, :class_name => 'ProductAttribute' if :parent_id
  acts_as_list :scope => :parent
end

As you can see, my goal is to have an attribute with a number of
children and a parent, as long as it's not a root attribute. I think I
got it right, but if you see any errors in this, please do tell me.

Now I want to list an entire product, with all its attributes, in a
view, which is where I got stuck. I want these associations to show
hierarchically, so that a child is in fact a child element ( for
example a list item ) of its parent. I can get all attributes using
the product_id, so I have defined a collection called @attributes in
my controller. But how to proceed in the view?

My guess is that I need a partial which loads itself, but how to pass
along the subcollection (a child -can- have another child which can
have another child and so on). It's important that it sorts every
subcollection (e.g. a few children of a certain child) by position: do
I have that covered in my model by :order => :position?

I really hope you can help.

Thank you!

Jaap Haagmans
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to