Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 Assets - Strange Serving in Development

I've got a problem with Rails 3.1 assets pipeline. Assets are included twice in development:

<script src="/assets/main_new.js?body=1" type="text/javascript"></script>
<script src="/assets/pagenav.js?body=1" type="text/javascript"></script>
<script src="/assets/tours.controller.js?body=1" type="text/javascript"></script>
<script src="/assets/tours.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>

Rails somehow compiles and includes application.js so all the scripts are included twice - as individual file and in application.js

Everything's fine with precompiled assets in production.

development.rb

 config.assets.compress = false
 config.assets.debug = true

production.rb

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false

# Compress both stylesheets and JavaScripts
config.assets.compress = true
config.assets.js_compressor  = :uglifier
config.assets.css_compressor = :scss

config.assets.compile = false
config.assets.digest = true

application.rb

config.assets.enabled = true
like image 885
Fenelon Avatar asked Dec 02 '11 12:12

Fenelon


2 Answers

Try adding the following to development.rb:

config.serve_static_assets = false

...and then clearing your browser cache (update based on comments)

The static assets refer to precompiled assets in public/assets, which is where rake assets:precompile puts them.

What's happening is that anything that exists in public/assets will override anything in app/assets if you are serving them. So public/assets/application.js is being loaded when the js tag is intending to identifiy app/assets/application.js.

like image 120
Ethan McCutchen Avatar answered Oct 23 '22 09:10

Ethan McCutchen


Once you get rid of /public/assets, you must also clear browser cache.

like image 12
Effisfor Avatar answered Oct 23 '22 07:10

Effisfor