我正在将我的Rails 3应用程序部署到Tomcat 6服务器。我一直在使用warble
将我的项目打包成war
文件,到目前为止还没有遇到任何麻烦。我刚刚在我的应用程序中添加了cache_sweeper
。当我尝试点击应用程序时,我收到了标准的500错误页面。
看着我的日志,我看到了:
org.jruby.rack.RackInitializationException: undefined method `cache_sweeper' for ApplicationController:Class
找不到cache_sweeper
方法?不是Rails的一部分吗?
在开发模式下不会发生这种情况,但在开发过程中,我使用MRI ruby并使用rails服务器。
任何人都有任何想法?!
完整错误:
SEVERE: Application Error
org.jruby.rack.RackInitializationException: undefined method `cache_sweeper' for ApplicationController:Class
from C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/app/controllers/application_controller.rb:239:in `require'
from C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/gems/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
from C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/gems/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:227:in `load_dependency'
from C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/gems/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
from C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/gems/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:346:in `require_or_load'
from C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/gems/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:491:in `load_missing_constant'
from C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/gems/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:183:in `const_missing'
from C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/gems/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:181:in `each'
... 39 levels...
from file:/C:/bin/apache-tomcat-6.0.29/webapps/rails3app/WEB-INF/lib/jruby-rack-1.0.3.jar!/vendor/rack-1.2.1/rack/builder.rb:46:in `initialize'
from <script>:2:in `new'
from <script>:2
at org.jruby.rack.DefaultRackApplicationFactory$4.init(DefaultRackApplicationFactory.java:184)
at org.jruby.rack.DefaultRackApplicationFactory.getApplication(DefaultRackApplicationFactory.java:59)
at org.jruby.rack.PoolingRackApplicationFactory.getApplication(PoolingRackApplicationFactory.java:94)
at org.jruby.rack.servlet.DefaultServletDispatcher.process(DefaultServletDispatcher.java:36)
at org.jruby.rack.RackFilter.doFilter(RackFilter.java:59)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
at java.lang.Thread.run(Thread.java:619)
答案 0 :(得分:0)
无论出于何种原因,在使用jruby / warble时都必须包含该模块。但是,使用MRI和rails服务器时,此步骤不是必需的。
我将此添加到我的ApplicationController
并且有效:
class ApplicationController < ActionController::Base
include ActionController::Caching::Sweeping if defined?(JRUBY_VERSION)
...
end