Take the 2-minute tour ×

hi people

I've follow this tutorial: http://railscasts.com/episodes/262-trees-with-ancestry

when I tried to make the "arrange (:order => :id)" I got this message

    undefined method `arrange' for #<Array:0x8c19780>

Extracted source (around line #4):

2: <h1>Listing categories</h1>
4: <%= nested_categories @categories.arrange(:order => :id) %>
6: <br />

Can you help me, please?


share|improve this question

3 Answers 3

up vote 4 down vote accepted

I'm using the ancestry Gem , and it works fine for me. e.g.:

 require 'awesome_print'                  # just for nice demo output
 ap  Account.arrange(:order => :id) ; 1   

You need to run it on your Categories class itself -- it's a class method

try it out in the Rails console!

share|improve this answer
so, the railscast is wrong??... do I have to change anything else in my code, because I did exactly the same steps. And where should I write that code you give me as example, in Model or Controller?? –  Angelo Oct 18 '11 at 21:01
already solved, thanks –  Angelo Oct 18 '11 at 21:08

I'll clarify @Tilo's answer:

In your Controller, do:

def index
  @categories = Category.arrange(:order => :created_at)

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @categories }

And in your View, do:

<%= nested_categories @categories %>

I'm using Rails 3, and the "Ancestry" gem seems like a great replacement for the "Acts As Tree" gem.

share|improve this answer

As I have described in this post ...

The arrange() method acts either at the class level or on a named scope, not on a returned array of values. For example, if you want to call arrange() on a table called 'Activity', this would work and return the entire table in an arranged format:


However, if you want to call arrange on a specific tree in the table you would go:


'subtree' is a named scope provided by the has_ancestry gem. Therefore, the arrange() method should work for the following named scope:

  • ancestors
  • children
  • sibblings
  • descendants
  • subtree
share|improve this answer

Your Answer


