Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4缓存未捕获更改_Ruby On Rails_Caching_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails Rails 4缓存未捕获更改

Ruby on rails Rails 4缓存未捕获更改,ruby-on-rails,caching,ruby-on-rails-4,Ruby On Rails,Caching,Ruby On Rails 4,我正在尝试使用Rails 4的片段缓存来缓存我的导航菜单 型号 class Page < ActiveRecord::Base belongs_to :parent, :class_name => 'Page', :touch => true has_many :children, :class_name => 'Page', :foreign_key => 'parent_id' ... end 为什么Rails无法识别页面中的更改

我正在尝试使用Rails 4的片段缓存来缓存我的导航菜单

型号

class Page < ActiveRecord::Base

  belongs_to :parent, :class_name => 'Page', :touch => true

  has_many :children, :class_name => 'Page', 
    :foreign_key => 'parent_id'

  ...

end

为什么Rails无法识别页面中的更改?

事实证明我的一切都是正确的,但是我的模型的范围:

scope :level_1, where(:level => 1)
默认情况下正在缓存,因为它不包含
lambda
。将范围更改为:

scope :level_1, -> { where(:level => 1) }
解决了我的问题,现在缓存摘要工作完美

scope :level_1, -> { where(:level => 1) }