Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript included twice in a Rails 3.1 asset-based app

Although the title of the question is very similar to a number of previous ones, my issue seems different.

Briefly, the first item in the js manifest is included twice.

Here's the whole of my /app/assets/javascript/application.js file in a Rails 3.1 application:

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require autocomplete-rails
//= require utilities

And here's a snippet of the rendered page's source:

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<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/autocomplete-rails.js?body=1" type="text/javascript"></script>
<script src="/assets/utilities.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>

Please note that if I move up to the top any of the other lines in application.js like so:

//= require utilities
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require autocomplete-rails

It is always the first item that gets included twice!

<script src="/assets/utilities.js?body=1" type="text/javascript"></script>
<script src="/assets/utilities.js?body=1" type="text/javascript"></script>
<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/autocomplete-rails.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>

UPDATE

As a temporary workaround, I added //= require dummy at the top of the list, which points to an empty dummy.js file. Although it appears twice in the rendered page, it has no effect, as it does nothing. On the other hand, if I set config.assets.debug = false in development.rb, as often suggested, then ALL of my javascript gets loaded twice:

<script src="/assets/application.js" type="text/javascript"></script>
<script src="/assets/application.js" type="text/javascript"></script>

and js actions are fired twice (e.g. confirm dialogs pop up twice when deleting a model)

Giuseppe

like image 332
Giuseppe Avatar asked Dec 03 '22 05:12

Giuseppe


1 Answers

I had faced something similar before and I just left a the first link blank and it worked for me. Give it a try.

/*leave the following line empty */

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require autocomplete-rails
//= require utilities
like image 94
Vosobe Kapsimanis Avatar answered Feb 16 '23 03:02

Vosobe Kapsimanis