Search code examples
ruby-on-railsancestry

Rails Ancestry gem rebuild cache


I'm using gem ancestry in a Rails3 app.

I am trying to change an existing model named sites to use the cache depth.

The documentation says this:

:cache_depth           Cache the depth of each node in the 'ancestry_depth' column (default: false)
                   If you turn depth_caching on for an existing model:
                   - Migrate: add_column [table], :ancestry_depth, :integer, :default => 0
                   - Build cache: TreeNode.rebuild_depth_cache!

I added the migration.

But, I don't understand how to execute the - Build cache: TreeNode.rebuild_depth_cache!

Where do I do that?

Thanks for your help!


Solution

  • Using the model that has ancestry. Example:

    class Site
      has_ancestry cache_depth: true
    end
    
    > Site.rebuild_depth_cache!