undefined method `cache_sweeper' for ActionController::Base:Class - warbler

960 views Asked by At

I am deploying my Jruby Rails application on glassfish with acts_as_audited as a gem/plugin installed.

Whenever I try to Audit my model, I am going to get the following error.

My Environment is: Jruby 1.6.0.RC2, Rails 3.0.3

You can refer here if you guys want to look more on the error http://www.ruby-forum.com/topic/1053934

Please help me out, I stuck up here

Application Error
org.jruby.rack.RackInitializationException: undefined method `cache_sweeper' for ActionController::Base:Class
    from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/acts_as_audited-2.0.0.rc6/lib/acts_as_audited.rb:44:in `class_eval'
    from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/acts_as_audited-2.0.0.rc6/lib/acts_as_audited.rb:44
    from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/acts_as_audited-2.0.0.rc6/lib/acts_as_audited.rb:68:in `require'
    from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
    from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
    from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `require'
    from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
    from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
     ... 20 levels...
2

There are 2 answers

0
zaadjis On BEST ANSWER

I reported this problema as a bug in jruby-rack.

A workaround is to add require 'active_record' if defined? $servlet_context after require 'rubygems' in config/boot.rb or manually including sweeping somwhere in application.rb ActionController::Base.send(:include, ActionController::Caching::Sweeping) if defined? $servlet_context.

5
Scott On

I think I recognise this problem. It looks like acts_as_audited uses cache sweepers. I've had this problem with cache sweepers.

You need to explicitly include the caching module in your ApplicationController:

class ApplicationController < ActionController::Base

  # JRuby not finding cache sweeper at runtime in production
  include ActionController::Caching::Sweeping if defined?(JRUBY_VERSION)

  # Rest of your class here...

end

I'm not sure why this happens, but it's probably a loading/resolution issue related to running in threadsafe mode for production.