JS文件双重包含在rails app中 [英] JS files double-included in rails app

查看:107
本文介绍了JS文件双重包含在rails app中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个rails 3.1应用程序,我在所有这些都遇到了这个问题。

I've got several rails 3.1 apps, and I'm having this problem in all of them.

我有一堆js文件包含在我的application.js文件。这是我的application.js:

I have a bunch of js files that get included in my application.js file. Here's my application.js:

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_self
//= require_tree .

问题在于,在开发.rb时,我将config.assets.debug设置为true,我的所有javascript文件都包含在标题中。实际上,它们并未明确地包含在内,而是单独包含一次,一次包含在已编译的application.js文件中。 js包含的标签如下所示:

The problem is that when, development.rb, I have config.assets.debug set to true, all of my javascript files get double-included in the header. Actually, they are not explicitly double-included, but rather they are included once individually and once as part of a compiled application.js file. The js include tags look like this:

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
<script src="/assets/animation_elements.js?body=1" type="text/javascript"></script>
<script src="/assets/categories.js?body=1" type="text/javascript"></script>
<script src="/assets/facebox.js?body=1" type="text/javascript"></script>
…

那到底是什么?结果是各种JQuery onClick()行为正在执行两次和其他废话。这有什么问题?为了记录,这是我的整个development.rb文件:

So what the hell? The result of this is that various JQuery onClick() behaviors are being performed twice and other nonsense. what's the problem here? For the record, here's my entire development.rb file:

Geobooks::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # In the development environment your application's code is reloaded on
  # every request.  This slows down response time but is perfect for development
  # since you don't have to restart the webserver when you make code changes.
  config.cache_classes = false

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  #config.action_view.debug_rjs             = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin

  #for devise
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

  # Do not compress assets
  config.assets.compress = false

  # Expands the lines which load the assets
  config.assets.debug = false
end


推荐答案

听起来好像您可能在某个时候预编译了您的资产。检查正在开发中提供的application.js文件的内容。我的猜测是你会看到所有其他所需文件的捆绑内容。要解决此问题,只需删除/public/assets/javascripts/application.js并退回服务器。

It sounds as if you may have precompiled your assets at some point. Check the contents of the application.js file that's being served in development. My guess is you'll see the bundled contents of all your other required files. To fix this, just delete /public/assets/javascripts/application.js and bounce your server.

如果不起作用,请确定第二个副本的位置来自(使用Firebug或类似的检查服务文件)并发布更新,我会看到我能做什么。

If that doesn't work, figure out where the second copy is coming from (using Firebug or similar to examine served files) and post an update and I'll see what I can do.

这篇关于JS文件双重包含在rails app中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆