JavaScript – JS文件双重包含在rails应用程序中

前端之家收集整理的这篇文章主要介绍了JavaScript – JS文件双重包含在rails应用程序中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有几个rails 3.1应用程序,我在所有这些问题.

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

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

问题是,当.development.rb,我的config.assets.debug设置为true时,我的所有javascript文件都被包含在标题中.实际上,它们没有被明确的双重包含,而是它们被单独包含,一次作为编译的application.js文件的一部分. js包含标签如下所示:

<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文件

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并弹出你的服务器.

如果这不起作用,找出第二个副本来自哪里(使用Firebug或类似的方式检查提供的文件)并发布更新,我将看到我能做什么.

猜你在找的JavaScript相关文章