我有几个rails 3.1应用程序,我在所有这些都遇到了这个问题。
我有一堆js文件包含在我的application.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
答案 0 :(得分:14)
听起来好像您可能在某个时候对您的资产进行了预编译。检查正在开发中提供的application.js文件的内容。我的猜测是你会看到所有其他所需文件的捆绑内容。要解决此问题,只需删除/public/assets/javascripts/application.js并退回服务器。
如果这不起作用,请确定第二个副本的来源(使用Firebug或类似方法检查提供的文件)并发布更新,我会看到我能做什么。