【问题标题】:Rails Ancestry gem rebuild cacheRails Ancestry gem 重建缓存
【发布时间】:2014-07-24 15:55:20
【问题描述】:

我在 Rails3 应用程序中使用 gem ancestry

我正在尝试更改名为站点的现有模型以使用缓存深度。

文档是这样说的:

: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!

我添加了迁移。

但是,我不明白如何执行- Build cache: TreeNode.rebuild_depth_cache!

我在哪里做呢?

感谢您的帮助!

【问题讨论】:

    标签: ruby-on-rails ancestry


    【解决方案1】:

    使用具有祖先的模型。示例:

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

    【讨论】:

    • 使用 Rails 控制台。 s = Site.new 给了我2.0.0p353 :001 > s = Site.new => #<Site id: nil, name: nil, description: nil, type_id: nil, tenant_id: nil, created_at: nil, updated_at: nil, address1: nil, address2: nil, city: nil, state: nil, zipcode: nil, ancestry: nil, position: nil, ancestry_depth: 0>
    • s.rebuild_depth_cache! 给了我NoMethodError: undefined method rebuild_depth_cache!'对于#<0x007fa000800618>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-09
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    相关资源
    最近更新 更多