1
我有我的控制器上:爲什麼鐵軌找不到我的清掃工?
class FormulariosController < ApplicationController
cache_sweeper :campanha_sweeper, :only => [:show]
# actions
end
我試圖創建一個名爲內部應用程序/清掃目錄,也沒有工作,我已經試過內部模型來創建一個/緩存文件夾(有一個以此爲例的博客)並沒有奏效。
我的清掃是這樣的:
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
末
我在嘗試啓動服務器以下時:
/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>'
爲什麼不工作?此外,是否有任何方法只會將視圖的緩存(如何呈現)放到緩存中。我在即時生成的意見,這將是非常有用的,如果我可以過期視圖的緩存位於說,views/formularios/a.html.rb
如果傢伙想知道我的'在做,這很簡單。我使用表單生成視圖,當我想更新視圖(或它的代碼),並且我正在生產時,視圖不會因緩存而更新,因此每次「更新」表單時都必須手動重置它的緩存。
謝謝。
我該怎麼做? – bcackerman 2012-11-17 21:45:47
如果'application.rb',你應該找到一條添加到'config.autoload_paths'的行。它最終應該看起來像'config.autoload_paths + =%W(#{Rails.root}/path/to/sweepers)'。可能還有其他自動加載路徑。 – x1a4 2012-11-18 02:27:46
好的,我這樣做了,並添加了'config.active_record.observers = [:order_sweeper]'。我在我的模型中有'cache_sweeper:order_sweeper',當我啓動我的服務器時仍然會出現一個錯誤'未初始化的常量OrderSweeper(NameError)'。任何想法有什麼不對? – bcackerman 2012-11-18 18:54:43