JS files double-included in rails app

放肆的年华 提交于 2019-12-10 01:57:07

问题


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

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 .

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>
…

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

回答1:


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.

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.



来源:https://stackoverflow.com/questions/8437574/js-files-double-included-in-rails-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!