Andrew S. wrote:
marek wrote:
I have a menu, that is hierarchical and stored according to nested set
model. i want to do this to have each “level” ordered alphabetically,
like this:
-country
–Andorra
–Belgium
–Norway
–Sweden
-food
–English
–Swedish
–Thai
In the example Country and Food must be ordered alphabetically, inside
country those countries must be ordered alphabetically and the cuisines
within food must be ordered alphabetically.
Is that possible?
Hope for help!
It depends a bit on how you are storing the menu items.
If they are all in one multi-dimensional array, try this:
a = [[“4”,“3”,“2”,“1”],[“2”,“3”,“1”]]
=> [[“4”,“3”,“2”,“1”],[“2”,“3”,“1”]]
a.collect{|x| x.sort}
=> [[“1”,“2”,“3”,“4”],[“1”,“2”,“3”]]
i’m storing it with create the category and then add it to a root or
parent category so i have for example
root
-country
–andorra
–norway
–belgium
-food
–thai
–english
i retrieve all them (to use with a select) with Category.find(:all,
:order => “lft”).map{|category| ["-" * category.depth + category.name,
category.id]}
and i have something like: [[“root”, 4], ["-contry", 5], ["–andorra",
7], ["–norway", 11], ["–belgium", 12], ["-food",14], ["–thai", 15],
["–english", 18]]
how can i get them, like your example, in a multidimensional array?