config.assets.debug如何导致我的Rails应用程序崩溃?

时间:2012-09-20 22:43:49

标签: ruby-on-rails arbor.js

我在我的Rails 3.2.8应用程序中包含了arbor-rails gem,它在开发模式下工作正常,但在生产中我收到以下错误:

Started GET "/nullarbor.js" for 127.0.0.1 at 2012-09-20 15:35:23 -0700

ActionController::RoutingError (No route matches [GET] "/nullarbor.js"):
  actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.8) lib/rails/engine.rb:479:in `call'
  railties (3.2.8) lib/rails/application.rb:223:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
  thin (1.4.1) lib/thin/connection.rb:80:in `block in pre_process'
  thin (1.4.1) lib/thin/connection.rb:78:in `catch'
  thin (1.4.1) lib/thin/connection.rb:78:in `pre_process'
  thin (1.4.1) lib/thin/connection.rb:53:in `process'
  thin (1.4.1) lib/thin/connection.rb:38:in `receive_data'
  eventmachine (1.0.0) lib/eventmachine.rb:187:in `run_machine'
  eventmachine (1.0.0) lib/eventmachine.rb:187:in `run'
  thin (1.4.1) lib/thin/backends/base.rb:63:in `start'
  thin (1.4.1) lib/thin/server.rb:159:in `start'
  rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
  rack (1.4.1) lib/rack/server.rb:265:in `start'
  railties (3.2.8) lib/rails/commands/server.rb:70:in `start'
  railties (3.2.8) lib/rails/commands.rb:55:in `block in <top (required)>'
  railties (3.2.8) lib/rails/commands.rb:50:in `tap'
  railties (3.2.8) lib/rails/commands.rb:50:in `<top (required)>'
  script/rails:6:in `require'
  script/rails:6:in `<main>'

我已完成environments/中的设置并发现当我在development.rb中设置以下内容时:

config.assets.debug = false

我也在开发模式下得到了错误。当我在生产中将它设置为true时,它可以正常工作。可能导致这种情况的原因是什么?

更新:实际上似乎与arbor.js中的arbor_path功能有关。

2 个答案:

答案 0 :(得分:3)

arbor.js使用web worker,这意味着您需要为Worker创建提供指向arbor.js脚本所在位置的相应链接。

解决此问题的方法是提供arbor.js文件的绝对路径,而不是让代码使用arbor_path函数,该函数可能会被缓存逻辑或js文件的服务方式弄乱。 / p>

换句话说,尝试替换

i=new Worker(arbor_path()+"arbor.js");

i=new Worker("/final/path/to/arbor.js");
arbor.js中的

答案 1 :(得分:0)

正如@ Asimov4所述,问题出现在以下电话中:

new Worker(arbor_path()+"arbor.js");

尽管如此,与资产预编译兼容的更优雅的解决方案是将其更改为:

new Worker("<%= asset_path('arbor.js') %>");

注意:请记住将.js文件更改为.js.erb!