2012-04-25 10 views
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>' 

なぜそれが動作しませんでしたか?また、(レンダリング方法の)ビューのみのキャッシュを期限切れにする方法はありますか。私はその場でビューを生成しています。ビュー/ formularios/a.html.rbにあるビューのキャッシュを期限切れにすることができれば非常に便利です。

私は、それは簡単です。私はフォームを使ってビューを生成し、そのビュー(またはそのコード)を更新したいときにプロダクションになると、ビューがキャッシュのために更新されないため、フォームを更新するたびに手動でキャッシュをリセットする必要があります。

ありがとうございました。

答えて

3

ディレクトリ(またはこれまでにスイーパコードを入力した場所)をautoload_pathsに追加しましたか?application.rb

+0

どうすればよいですか? – bcackerman

+0

'application.rb'の場合、' config.autoload_paths'に追加する行が見つかるはずです。 'config.autoload_paths + =%W(#{Rails.root}/path/to/sweepers)'のようなものになります。他の自動ロードパスが既に存在する可能性があります。 – x1a4

+0

私はそれを行い、 'config.active_record.observers = [:order_sweeper]'も加えました。私はモデルに 'cache_sweeper:order_sweeper'を持っていて、サーバを起動するときに' uninitialized constant OrderSweeper(NameError) 'というエラーが発生します。どのようなアイデアが間違っている? – bcackerman