Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.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可以';我找不到我的清洁工?_Ruby On Rails_Ruby On Rails 3_Sweeper - Fatal编程技术网

Ruby on rails 为什么rails可以';我找不到我的清洁工?

Ruby on rails 为什么rails可以';我找不到我的清洁工?,ruby-on-rails,ruby-on-rails-3,sweeper,Ruby On Rails,Ruby On Rails 3,Sweeper,我的控制器上有: class FormulariosController < ApplicationController cache_sweeper :campanha_sweeper, :only => [:show] # actions end class formularoscontroller[:show] #行动 结束 我试着在app内部创建一个名为/sweepers的目录,但它不起作用,我试着在models内部创建一个/cache文件夹(有一个博客使

我的控制器上有:

class FormulariosController < ApplicationController
    cache_sweeper :campanha_sweeper, :only => [:show]

    # actions
end
class formularoscontroller[:show]
#行动
结束
我试着在app内部创建一个名为/sweepers的目录,但它不起作用,我试着在models内部创建一个/cache文件夹(有一个博客使用了这个例子),但它不起作用

我的清扫器看起来像这样:

class CampanhaSweeper < ActionController::Caching::Sweeper
  observe Campanha

  def after_update(campanha)
    expire_cache_for(campanha)
  end

  private
  def expire_cache_for(campanha)
    expire_page(:controller => 'formularios', :action => 'show')

    ap "Expired cache for formularios#show in formulariosweeper"
  end
class CampanhaSweeper'formularios',:action=>'show')
ap“formularios的过期缓存#在formulariosweeper中显示”
结束
结束

我在尝试启动服务器时遇到以下问题:

/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.12/lib/action_controller/caching/sweeping.rb:41:in `const_get': uninitialized constant CampanhaSweeper (NameError)
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.12/lib/action_controller/caching/sweeping.rb:41:in `block in cache_sweeper'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.12/lib/action_controller/caching/sweeping.rb:39:in `each'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.12/lib/action_controller/caching/sweeping.rb:39:in `cache_sweeper'
    from /Users/thiagomassa/Projects-ginga/ginga-campanhas/app/controllers/formularios_controller.rb:2:in `<class:FormulariosController>'
    from /Users/thiagomassa/Projects-ginga/ginga-campanhas/app/controllers/formularios_controller.rb:1:in `<top (required)>'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:137:in `each'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:137:in `block in eager_load!'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:135:in `each'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:135:in `eager_load!'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/application.rb:108:in `eager_load!'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:25:in `run'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:49:in `each'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/application.rb:134:in `initialize!'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/application.rb:77:in `method_missing'
    from /Users/thiagomassa/Projects-ginga/ginga-campanhas/config/environment.rb:5:in `<top (required)>'
    from /Users/thiagomassa/Projects-ginga/ginga-campanhas/config.ru:3:in `block in <main>'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/builder.rb:46:in `instance_eval'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/builder.rb:46:in `initialize'
    from /Users/thiagomassa/Projects-ginga/ginga-campanhas/config.ru:1:in `new'
    from /Users/thiagomassa/Projects-ginga/ginga-campanhas/config.ru:1:in `<main>'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/builder.rb:35:in `eval'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/builder.rb:35:in `parse_file'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/server.rb:162:in `app'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/server.rb:253:in `wrapped_app'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/server.rb:204:in `start'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/commands/server.rb:65:in `start'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/commands.rb:30:in `block in <top (required)>'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/commands.rb:27:in `tap'
    from /Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/commands.rb:27:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.12/lib/action\u controller/caching/sweeping.rb:41:in'const\u get':未初始化常量CampanhaSweeper(NameError)
来自/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.12/lib/action\u controller/caching/sweeping.rb:41:“缓存中的块\u sweepper”
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.12/lib/action\u controller/caching/sweeping.rb:39:in'each'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.12/lib/action\u controller/caching/sweeping.rb:39:in'cache\u sweepper'
from/Users/thiagomassa/Projects ginga/ginga campanhas/app/controllers/formularios_controller.rb:2:in`'
from/Users/thiagomassa/Projects ginga/ginga campanhas/app/controllers/formularios_controller.rb:1:in`'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:138:in`block(2层)in eager_load!'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:137:in'each'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:137:in'block in eager_load!'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:135:in'each'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/engine.rb:135:in'eager_load!'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/application.rb:108:in'eager_load!'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/application/finisher.rb:41:in'block in'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:25:in'instance_exec'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:25:in'run'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:50:“运行中的块初始化器”
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:49:in'each'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/initializable.rb:49:in'run_initializers'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/application.rb:134:in'initialize!'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/application.rb:77:in'method_missing'
from/Users/thiagomassa/Projects-ginga/ginga-campanhas/config/environment.rb:5:in`'
from/Users/thiagomassa/Projects-ginga/ginga-campanhas/config.ru:3:in'block-in'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/builder.rb:46:in'instance_eval'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/builder.rb:46:in'initialize'
from/Users/thiagomassa/Projects-ginga/ginga-campanhas/config.ru:1:in'new'
from/Users/thiagomassa/Projects-ginga/ginga-campanhas/config.ru:1:in`'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/builder.rb:35:in'eval'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/builder.rb:35:in'parse_file'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/server.rb:162:in'app'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/server.rb:253:in'wrapp'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.5/lib/rack/server.rb:204:在“开始”中
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/commands/server.rb:65:in'start'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/commands.rb:30:in'block in'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/commands.rb:27:in'tap'
from/Users/thiagomassa/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.12/lib/rails/commands.rb:27:in`'
来自脚本/rails:6:in'require'
来自脚本/rails:6:in`'
为什么不起作用?另外,是否有任何方法可以使仅一个视图的缓存过期(它是如何呈现的)。我正在动态生成视图,如果我可以使位于views/formularios/a.html.rb的视图的缓存过期,这将非常有用

如果男人想知道我在做什么,很简单。我使用表单生成视图,当我想更新该视图(或其代码)并且我正在生产时,由于缓存,该视图不会得到更新,因此每次“更新”表单时,我都必须手动重置其缓存


谢谢。

您是否在
应用程序.rb
中的
自动加载路径
中添加了
清扫器
目录(或放置清扫器代码的位置)?

如果
应用程序.rb
,您应该会找到一行添加到
配置自动加载路径
。它的最终外观应该类似于
config.autoload_path+=%W(#{Rails.root}/path/to/sweeppers)
。可能已经有其他自动加载路径了。好的,我这样做了,并添加了
config.active\u rec