2

我正在 glassfish 上部署我的 Jruby Rails 应用程序,并acts_as_audited安装了 gem/plugin。

每当我尝试审核我的模型时,我都会收到以下错误。

我的环境是:Jruby 1.6.0.RC2,Rails 3.0.3

如果你们想了解更多关于错误的信息,可以参考这里http://www.ruby-forum.com/topic/1053934

请帮帮我,我卡在这里

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...
4

2 回答 2

1

我想我认识到了这个问题。看起来acts_as_audited 使用了缓存清扫器。我在使用缓存清扫器时遇到过这个问题。

您需要在 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

我不确定为什么会发生这种情况,但这可能是与在生产的线程安全模式下运行相关的加载/解决问题。

于 2011-02-14T11:35:13.100 回答
1

我将此问题报告为jruby-rack 中的错误

一种解决方法是在 config/boot.rb 中添加require 'active_record' if defined? $servlet_contextafterrequire 'rubygems'或手动在 application.rb 中包括清扫 somwhere ActionController::Base.send(:include, ActionController::Caching::Sweeping) if defined? $servlet_context

于 2011-06-28T14:07:15.623 回答