Help: awesome_nested_set

hi,

how can i select & build a recursive xml-response of all roots (PLURAL)
?meaning not only 1st-level-children, but all level…

eg

FaqCategory.find(:all, :conditions => [‘parent_id IS
NULL’]).ALL.full_set

but for some reason, i dont get it…

help

thx

hi, i think u didnt understand my question:

how do i get ALL roots PLUS all descendants in one go?

res = Category.find(all, conditions{parent_id IS NULL})
res.descendants

descendants works only on a result of size of 1

regs

Tom T. wrote:

hi,

how can i select & build a recursive xml-response of all roots (PLURAL)
?meaning not only 1st-level-children, but all level…

That’s what the Model#descendants method in awesome_nested_set does. Go
read the rdoc – it’s brief but clear.

eg

FaqCategory.find(:all, :conditions => [‘parent_id IS
NULL’]).ALL.full_set

What the heck is that?

but for some reason, i dont get it…

The docs are your friend. Also, there are some articles on the Web
about the basics of the nested set concept. You should probably read
some of them.

help

thx

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

im looking at it right now, but it doesnt look promising. seems i have
to play around with the xml-builder again. any other ideas?

regs

Tom T. wrote:

hi, i think u didnt understand my question:

how do i get ALL roots PLUS all descendants in one go?

I remember that there’s a way to do this (besides find :all), but you’ll
have to check the docs. If you can’t find it after reading the docs,
let me know.

res = Category.find(all, conditions{parent_id IS NULL})
res.descendants

descendants works only on a result of size of 1

Of course. res is an Array, while descendants is defined on Category.

regs

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

hi,

ok, what i need and dont know know how to do is:

@result = Category.roots
#gives me 3, because i have 3 records with parent_id=NULL, what is fine

@result.TO_FULL_RECURSIVE_XML

#######
again, i want a xml-structure of all root-records with their children,
and their children , and their children etc…

i can do it if i have only 1 result, but dont know how to build the xml
if i have, lets say 30+ roots…

thx

Tom T. wrote:

hi,

ok, what i need and dont know know how to do is:

@result = Category.roots
#gives me 3, because i have 3 records with parent_id=NULL, what is fine

@result.TO_FULL_RECURSIVE_XML

You might just want to do Category.find :all, :order => ‘lft’, which
will give you all the records in the right order. Alternatively, you
could make all 3 current root elements into children of a new, single,
root, and then just fetch all descendants of the new root.

#######
again, i want a xml-structure of all root-records with their children,
and their children , and their children etc…

i can do it if i have only 1 result, but dont know how to build the xml
if i have, lets say 30+ roots…

thx

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

yeah, i tried that too, but that underlaying issue here is the recursiv
xml…
thx anyway for ur help.

Tom T. wrote:

im looking at it right now, but it doesnt look promising. seems i have
to play around with the xml-builder again. any other ideas?

You can use awesome_nested_set for what you’re describing. What do you
mean when you say it “doesn’t look promising”? Where’s the problem?
What don’t you understand?

regs

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Tom T. wrote:

yeah, i tried that too, but that underlaying issue here is the recursiv
xml…

Once you’ve got the array in memory, it’s not hugely difficult to step
through it and generate XML. What isn’t working?

thx anyway for ur help.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

ok,

this is a function, sitting on my model: category.rb

######################################################################
A )
##########
def full_xml(builder=nil)
to_xml(:builder => builder, :skip_instruct => true) do |xml|
children.each { |child| child.full_xml(xml) }
end
end
##########

so when i call:

@category = Category.find params[:id]

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @category.full_xml}
end

i get a nice recursiv xml data.

######################################################################
B) in this case
@categorIES = Category.roots #means all with parent_id IS NULL
but i dont know how to itereate thorugh to build that xml again…

any ideas?

thx

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs