2

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 Answers 2

1

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.

1

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.

5
  • UPDATE: I've since discovered the following Rails Lighthouse ticket that suggests that the sweeper is not threadsafe. You may run into other issues. However, there is a workaround. rails.lighthouseapp.com/projects/8994/tickets/…
    – Scott
    Feb 14, 2011 at 13:26
  • Hi Scott,Thank you for your answer. I did it before and even tried now, but it didnt work for me. The same error is repeated.
    – kill007
    Feb 14, 2011 at 19:00
  • I even tried to load action_controller in all the ways I know, but my bad I dont know whats wrong Im doing.
    – kill007
    Feb 15, 2011 at 20:48
  • I've just realised what the answer might be. I've just looked at the source to acts_as_audited on Github... Look at the line that is throwing the error: github.com/collectiveidea/acts_as_audited/blob/master/lib/… See that it is the same error that my answer fixes, but it is probably occurring earlier than my fix in ApplicationController, so if you patch the gem source in the same manner, i.e. put 'include ActionController::Caching::Sweeping' before line 45, it will probably work. Does this make sense?
    – Scott
    Feb 15, 2011 at 21:03
  • I tried even that but couldn't resolve it. I don't know what wrong with it or what's wrong I am doing. The weird thing is it works in development and I am unable to deploy it on glassfish. I tried to run it on webrick in production envi and its fine there. I think its breaking because of warble
    – kill007
    Mar 2, 2011 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.